您的位置:首页 > 其它

onTouchEvent方法介绍

2015-12-18 14:04 253 查看
onTouchEvent方法记录触屏动作和触屏位置。

下面我们来看一下代码。

代码其实很简单,就是两个TextView控件,第一个记录触屏事件,第二个记录触屏位置。

然后设置一个外部类

public boolean onTouchEvent(MotionEvent event) {

int Action=event.getAction();

float X=event.getX();

float Y=event.getY();

Log.v(TAG, "Action="+Action);

Log.v(TAG, "("+X+","+Y+")");

mAction.setText("Action="+Action);

mpostion.setText("Position=("+X+","+Y+")");

return true;

}

然后运行程序就可以了。其中的Log在前面的介绍中有提到。



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: