我想在我的活动中设置图像按钮(pushClick),以启用用于旋转针图形的onTouchEvents。不幸的是,无论我是否点击图像按钮,onTouchEvent都处于活动状态。我怎样才能防止onTouchEvent发射,直到点击图像按钮后?开始onTouchEvent之后onClick事件
public void pushClick(View pushClick) {
switch (pushClick.getId()) {
case R.id.btn_push:
make(degrees);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startRotating();
break;
case MotionEvent.ACTION_UP:
stopRotating();
break;
}
return super.onTouchEvent(event);
}
private void startRotating() {
returnRotating = false;
if (!keepRotating) {
keepRotating = true;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (keepRotating) {
degrees = (degrees + 1) % 360;
make(degrees);
handler.postDelayed(this, INTERVAL);
}
}
}, INTERVAL);
}
}
private void stopRotating() {
keepRotating = false;
if (!returnRotating) {
returnRotating = true;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (returnRotating) {
degrees = (degrees - 1) % 360;
make(degrees);
handler.postDelayed(this, INTERVAL);
}
}
}, INTERVAL);
}
}
这实际上就像一个魅力!我试图找出如何使用int将on()添加到onTouchEvent,但是有很多语法问题。万分感谢! – n00bdev