android 的touch event分析
01 |
<?xml version="1.0" encoding="utf-8"?> |
02 |
<test.lzqdiy.MyLinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" |
03 |
android:orientation="vertical" |
04 |
android:layout_width="fill_parent" |
05 |
android:layout_height="fill_parent" |
06 |
android:gravity="center" > |
07 |
<test.lzqdiy.MyTextView |
08 |
android:layout_width="200px" |
09 |
android:layout_height="200px" |
10 |
android:id="@+id/tv" |
11 |
android:text="lzqdiy" |
12 |
android:textSize="40sp" |
13 |
android:textStyle="bold" |
14 |
android:background="#FFFFFF" |
15 |
android:textColor="#0000FF"/> |
16 |
</test.lzqdiy.MyLinearLayout> |
001 |
package test.lzqdiy; |
002 |
003 |
import android.app.Activity; |
004 |
import android.os.Bundle; |
005 |
006 |
public class TestTouchEventApp extends Activity { |
007 |
/** Called when the activity is first created. */ |
008 |
@Override |
009 |
public void onCreate(Bundle savedInstanceState) { |
010 |
super.onCreate(savedInstanceState); |
011 |
setContentView(R.layout.main); |
012 |
} |
013 |
} |
014 |
package test.lzqdiy; |
015 |
016 |
import android.content.Context; |
017 |
import android.util.AttributeSet; |
018 |
import android.util.Log; |
019 |
import android.view.MotionEvent; |
020 |
import android.widget.LinearLayout; |
021 |
022 |
public class MyLinearLayout extends LinearLayout { |
023 |
private final String TAG = "MyLinearLayout"; |
024 |
025 |
public MyLinearLayout(Context context, AttributeSet attrs) { |
026 |
027 |
super(context, attrs); |
028 |
029 |
Log.d(TAG, TAG); |
030 |
031 |
} |
032 |
033 |
@Override |
034 |
public boolean dispatchTouchEvent(MotionEvent ev) { |
035 |
int action = ev.getAction(); |
036 |
037 |
switch (action) { |
038 |
039 |
case MotionEvent.ACTION_DOWN: |
040 |
041 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_DOWN"); |
042 |
043 |
break; |
044 |
045 |
case MotionEvent.ACTION_MOVE: |
046 |
047 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_MOVE"); |
048 |
049 |
break; |
050 |
051 |
case MotionEvent.ACTION_UP: |
052 |
053 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_UP"); |
054 |
055 |
break; |
056 |
057 |
case MotionEvent.ACTION_CANCEL: |
058 |
059 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_CANCEL"); |
060 |
061 |
break; |
062 |
063 |
} |
064 |
return super.dispatchTouchEvent(ev); |
065 |
} |
066 |
067 |
@Override |
068 |
public boolean onInterceptTouchEvent(MotionEvent ev) { |
069 |
070 |
int action = ev.getAction(); |
071 |
072 |
switch (action) { |
073 |
074 |
case MotionEvent.ACTION_DOWN: |
075 |
076 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_DOWN"); |
077 |
078 |
break; |
079 |
080 |
case MotionEvent.ACTION_MOVE: |
081 |
082 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_MOVE"); |
083 |
084 |
break; |
085 |
086 |
case MotionEvent.ACTION_UP: |
087 |
088 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_UP"); |
089 |
090 |
break; |
091 |
092 |
case MotionEvent.ACTION_CANCEL: |
093 |
094 |
Log.d(TAG, "onInterceptTouchEvent action:ACTION_CANCEL"); |
095 |
096 |
break; |
097 |
098 |
} |
099 |
100 |
return false; |
101 |
102 |
} |
103 |
104 |
@Override |
105 |
public boolean onTouchEvent(MotionEvent ev) { |
106 |
107 |
int action = ev.getAction(); |
108 |
109 |
switch (action) { |
110 |
111 |
case MotionEvent.ACTION_DOWN: |
112 |
113 |
Log.d(TAG, "---onTouchEvent action:ACTION_DOWN"); |
114 |
115 |
break; |
116 |
117 |
case MotionEvent.ACTION_MOVE: |
118 |
119 |
Log.d(TAG, "---onTouchEvent action:ACTION_MOVE"); |
120 |
121 |
break; |
122 |
123 |
case MotionEvent.ACTION_UP: |
124 |
125 |
Log.d(TAG, "---onTouchEvent action:ACTION_UP"); |
126 |
127 |
break; |
128 |
129 |
case MotionEvent.ACTION_CANCEL: |
130 |
131 |
Log.d(TAG, "---onTouchEvent action:ACTION_CANCEL"); |
132 |
133 |
break; |
134 |
135 |
} |
136 |
137 |
return true; |
138 |
} |
139 |
140 |
} |
141 |
package test.lzqdiy; |
142 |
143 |
import android.content.Context; |
144 |
import android.util.AttributeSet; |
145 |
import android.util.Log; |
146 |
import android.view.MotionEvent; |
147 |
import android.widget.TextView; |
148 |
149 |
public class MyTextView extends TextView { |
150 |
151 |
private final String TAG = "MyTextView"; |
152 |
153 |
public MyTextView(Context context, AttributeSet attrs) { |
154 |
155 |
super(context, attrs); |
156 |
157 |
} |
158 |
159 |
@Override |
160 |
public boolean dispatchTouchEvent(MotionEvent ev) { |
161 |
int action = ev.getAction(); |
162 |
163 |
switch (action) { |
164 |
165 |
case MotionEvent.ACTION_DOWN: |
166 |
167 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_DOWN"); |
168 |
169 |
break; |
170 |
171 |
case MotionEvent.ACTION_MOVE: |
172 |
173 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_MOVE"); |
174 |
175 |
break; |
176 |
177 |
case MotionEvent.ACTION_UP: |
178 |
179 |
Log.d(TAG, "dispatchTouchEvent action:ACTION_UP"); |
180 |
181 |
break; |
182 |
183 |
case MotionEvent.ACTION_CANCEL: |
184 |
185 |
Log.d(TAG, "onTouchEvent action:ACTION_CANCEL"); |
186 |
187 |
break; |
188 |
189 |
} |
190 |
return super.dispatchTouchEvent(ev); |
191 |
} |
192 |
193 |
@Override |
194 |
public boolean onTouchEvent(MotionEvent ev) { |
195 |
196 |
int action = ev.getAction(); |
197 |
198 |
switch (action) { |
199 |
200 |
case MotionEvent.ACTION_DOWN: |
201 |
202 |
Log.d(TAG, "---onTouchEvent action:ACTION_DOWN"); |
203 |
204 |
break; |
205 |
206 |
case MotionEvent.ACTION_MOVE: |
207 |
208 |
Log.d(TAG, "---onTouchEvent action:ACTION_MOVE"); |
209 |
210 |
break; |
211 |
212 |
case MotionEvent.ACTION_UP: |
213 |
214 |
Log.d(TAG, "---onTouchEvent action:ACTION_UP"); |
215 |
216 |
break; |
217 |
218 |
case MotionEvent.ACTION_CANCEL: |
219 |
220 |
Log.d(TAG, "---onTouchEvent action:ACTION_CANCEL"); |
221 |
222 |
break; |
223 |
224 |
} |
225 |
226 |
return true; |
227 |
228 |
} |
229 |
230 |
} |
android 的touch event分析的更多相关文章
- Android中Touch事件分析--解决HorizontalScrollView滑动和按钮事件触发问题
之前写过关于HorizontalScrollView滑动和按钮事件触发问题,但是不能所有的情况,最近几天一直在想这个问题,今天有一个比较好的解决思路,最终应用在项目里面效果也很好,首先说明一下功能: ...
- Android判断Touch为滑动事件还是操作控件
Android判断Touch为滑动事件还是操作控件 因为在项目中要判断WebView是否处于滚动状态,但它不像ListView有onScrollStateChanged方法来监听,要实现就得手动监听它 ...
- Android的Touch事件处理机制
Android的Touch事件处理机制比较复杂,特别是在考虑了多点触摸以及事件拦截之后. Android的Touch事件处理分3个层面:Activity层,ViewGroup层,View层. 首先说一 ...
- MonkeyRunner 连续两次点击报“Error sending touch event”
最近用monkeyrunner做自动化测试,遇到连续两次点击,第二次点击就会报错“Error sending touch event”. 具体做法如下: device.touch(234,112, ' ...
- Android四个多线程分析:MessageQueue实现
Android四个多线程分析:MessageQueue的实现 罗朝辉 (http://blog.csdn.net/kesalin) CC 许可,转载请注明出处 在前面两篇文章<Android多线 ...
- Html5 touch event
HTML5 for the Mobile Web: Touch Events POSTED BY RUADHAN - 15 AUG 2013 See also... Touch-friendly Dr ...
- Android Choreographer 源码分析
Choreographer 的作用主要是配合 Vsync ,给上层 App 的渲染提供一个稳定的 Message 处理的时机,也就是 Vsync 到来的时候 ,系统通过对 Vsync 信号周期的调整, ...
- android wifi ANR问题分析总结
android wifi ANR问题分析总结 1 看看main进程阻塞在那里? 2 调用关系的函数阻塞在那里? 3 最终阻塞函数的阻塞前的log以及状态
- Touch Event
转自: http://hi.baidu.com/masaiui/item/971775e8b316238bc10d754b 参考: http://hedgehogking.com/?p=55 ...
随机推荐
- XE6移动开发环境搭建之IOS篇(9):配置XE6的IOS SDK(有图有真相)
网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 1.开启PAServ ...
- Mysql备份迁移——MySqlBackup(.net)——(无法解决视图嵌视图报错)
这里是利用MySqlBackup,可以再nuget中下载. 无法解决视图嵌视图报错的问题,只导表跟数据比较合适,如果有视图嵌视图,请参照Mysql备份迁移——Mysqldump(.NET调用Mysql ...
- C#加密解密(DES,AES,Base64,md5,SHA256,RSA,RC4)
一:异或^简单加解密(数字类型) 1:原理: 异或用于比较两个二进制数的相应位,在执行按位"异或"运算时,如果两个二进制数的相应位都为1或者都为0,则返回0;如果两个二进制数的相应 ...
- Monty Hall Problem的一个图解,感觉不错
从Coursera.org上的台大概率课讨论组里拿来的 如果不转换,选中汽车的概率是1/3,非常显然. 但转换后选中汽车的概率变成2/3就有点反直觉了,并不是太容易想明白. 因为转换其实有4种:汽车- ...
- tiny学习3
这几天在埋头写自己的个星期!而且由于它是基于事件发生的次序(小时就把我的文件导出来了--呵呵.在阅读本文之前,请先看看我Blog里转贴的<TinyXML学习笔记>,相信它能给各位一个关于T ...
- LINUX下查看负载
1,查看磁盘 df -h 2,查看内存大小 free free [-m|g]按MB,GB显示内存 vmstat 3,查看cpu cat /proc/cpuinfo 只看cpu数量grep " ...
- MSsql 服务器之间远程及其链接查询
先指定端口1433(SQL,协议里面设置) 然后启用 菜单-程序-外围服务应用配置-服务和连接时外围应用配置 试试远程连接 成功连接OK 下面示例链接服务器.上面远程是必须走的一步动作. --创建链接 ...
- 微信 网页授权获取用户基本信息(OAuth 2.0)
// 相关设置 $APPID = ""; $AppSecret = ""; $html = ""; // 拼接 URL // 跳转该连接 获 ...
- JavaScript Function(函数表达式)
创建函数 创建函数的方式有两种:1.函数声明,2.函数表达式 函数声明的语法为 functionName(); //不会报错,函数声明提升function functionName(arg0,arg1 ...
- 无法使用内置管理员账户打开Microsoft Edge
一.以管理员批准模式运行所有管理员 运行"gpedit.msc",打开本地组策略编辑器,然后依次打开"计算机配置→Windows 设置→安全设置→本地策略→安全选项&qu ...