安卓的触摸方法–回调
当用户触摸的时候自动调用的方法
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
{
System.out.println("按下");
}
break;
case MotionEvent.ACTION_MOVE:
{
System.out.println("移动");
}
break;
case MotionEvent.ACTION_CANCEL:
{
System.out.println("取消");
}
break;
case MotionEvent.ACTION_OUTSIDE:
{
System.out.println("ACTION_OUTSIDE");
}
break;
case MotionEvent.ACTION_UP:
{
System.out.println("弹起");
}
break;
default:
break;
}
return super.onTouchEvent(event);
}
本文详细介绍了安卓应用程序中处理触摸事件的方法。通过重写onTouchEvent方法并利用MotionEvent的不同动作常量,可以实现对用户触摸屏幕行为的精确响应,包括按下、移动、取消、超出有效区域及手指抬起等。

2010

被折叠的 条评论
为什么被折叠?



