sách gpt4 ai đã đi

OnTouchListener trong View bên trong ScrollView

In lại 作者:行者123 更新时间:2023-11-30 05:07:32 28 4
mua khóa gpt4 Nike

我在 ScrollView 中有一个 View 。只要用户按住该 View ,我想每 80 毫秒调用一次方法。这是我已经实现的:

final Runnable vibrate = new Runnable() {
công khai void run() {
vibrate();
}
};

theView.setOnTouchListener(new View.OnTouchListener() {
@Ghi đè
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
final ScheduledFuture vibrateHandle =
scheduler.scheduleAtFixedRate(vibrate, 0, 80, MILLISECONDS);
vibrateHanlers.add(vibrateHandle);
trả về giá trị đúng;
}
if (motionEvent.getAction() == MotionEvent.ACTION_CANCEL
|| motionEvent.getAction() == MotionEvent.ACTION_UP) {
clearAllScheduledFutures();
trả về false;
}
trả về giá trị đúng;
}
});

问题是,ACTION_CANCEL 是为手指的最小移动而调用的。我知道这是因为 Xem nằm trong ScrollView 内,但我不确定我在这里有什么选择。我是否创建自定义 ScrollView,并尝试查找是否触摸了所需的 View 并禁用 ScrollView 的触摸事件?或者,为小的移动阈值禁用 SrollView 的触摸事件?还是别的?

1 Câu trả lời

您能否尝试在 ActionUp 事件中返回 true 而不是 false,这样该事件被视为已消耗

if (motionEvent.getAction() == MotionEvent.ACTION_CANCEL
|| motionEvent.getAction() == MotionEvent.ACTION_UP) {
clearAllScheduledFutures();
trả về giá trị đúng;
}

关于android - ScrollView 中的 View 中的 OnTouchListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54306299/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com