我已经问过这个问题,但当时我认为 onTouch 事件之间的刷新时间是我的问题 Android onTouch refresh rate .但事实并非如此。又是我的问题: 当我的手指触摸显示屏时,我需要一个向左/向右/向上移动的 Sprite。所以我的 onTouchEvent 返回 true。但这只有在我的手指轻扫一下或者触摸屏驱动程序如此糟糕以至于它抖动如此之多而被检测为手指移动时才有效。 我想到了线程的解决方案。所以我启动了一个正在移动播放器的线程,当手指抬起时它会被中断。但也许有更好的方法来做到这一点?
@Override
public boolean onTouchEvent(MotionEvent me) {
...
if (me.getY() < getHeight() / 2) {
return doAction(0);
} else if (me.getX() >= getWidth() / 2)
return doAction(2);
else if (me.getX() < getWidth() / 2)
return doAction(1);
//doAction returns TRUE
...
最佳答案
final Button b=(Button)findViewById(R.id.button1);
b.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
b.setBackgroundResource(R.drawable.ic_launcher);
finish();
return true;
case MotionEvent.ACTION_DOWN:
//work u want to do etc ..use all the events like this
}
b.setBackgroundResource(R.drawable.ic_back);
return false;
}
});
关于android - 手指向下做一些 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11258397/