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在前面的介绍中有提到。
下面我们来看一下代码。
代码其实很简单,就是两个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在前面的介绍中有提到。
相关文章推荐
- bootstrap导航条、分页导航学习笔记6-3(为导航条添加标题、二级菜单及状态)
- iOS 深入理解UINavigationController 和 UIViewController 之间的关系
- 跟着韩老师学HTML5的tank大战一些问题和代码
- Python Beginner
- struts2+hibernate+spring配置详解
- object-c 宏定义
- 交换两个变量的值(多种方法)
- JavaScript验证手机号是否正确(正则表达式)
- 无法解析的外部符号
- vim 插件 通过vundle 安装 tagbar
- 比较选择的开始时间和结束时间的大小
- C#应用调试C++ dll的方法
- php 在服务器端开启错误日志记录方法
- Javascript生成GUID
- 测试网页兼容性的一个服务很好用.
- Dedecms channel 标签 指定typeid时 currentstyle无效的修复办法
- ubuntu防火墙配置
- 宝宅智能家居-开源的智能家居开发平台
- 各种分类算法的优缺点
- android 简单粗暴的注解初始化View学习