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 ...
随机推荐
- sql server 2008 r2 报错
无法启动服务,要求检查数据库和windows日志 查看发现报错 The SQL Server failed to initialize VIA support library [QLVipl.dll] ...
- [家里蹲大学数学杂志]第013期2010年西安偏微分方程暑期班试题---NSE,非线性椭圆,平均曲率流,非线性守恒律,拟微分算子
Navier-Stokes equations 1 Let $\omega$ be a domain in $\bbR^3$, complement of a compact set $\mathca ...
- CSS布局概述
1.HTML5文档类型 由于Bootstrap使用了HTML5特定的HTML元素和CSS属性,所以使用Bootstrap的时候,所有的HTML文件都需要在其顶部引用HTML5的DOCTYPE属性,如下 ...
- 如何查看oracle数据库告警日志
目标:查看alert日志 su - oracle cd $ORACLE_BASE/diag/rdbms/LXY/LXY/trace tail -100f alert_LXY.log 我的ORACLE_ ...
- 在Spring的bean中注入HttpServletRequest解密
我们可以在Spring的bean中轻松的注入HttpServletRequest,使用@Autowired HttpServletRequest request;就可以了. 但是,为什么我们可以直接这 ...
- [ActionScritp 3.0] 使用LocalConnection建立通信
包 flash.net 类 public class LocalConnection 继承 LocalConnection → EventDispatcher → Object 语言版本: Acti ...
- Relatives
Description Given n, a positive integer, how many positive integers less than n are relatively prime ...
- JDBC事务处理
关于事务: 1.一个事务中的多个操作应该公用一个connection,如果每一个操作都用不同的connection,事务将无法回滚. 2.具体步骤: 1).在事务开始前,应该取消事务的自动提交,即设置 ...
- Sqoop2入门之导入关系型数据库数据到HDFS上(sqoop2-1.99.4版本)
sqoop2-1.99.4和sqoop2-1.99.3版本操作略有不同:新版本中使用link代替了老版本的connection,其他使用类似. sqoop2-1.99.4环境搭建参见:Sqoop2环境 ...
- linux下查找某个文件位置的方法
一.通过文件名查找法: 举例说明,假设你忘记了httpd.conf这个文件在系统的哪个目录 下,甚至在系统的某个地方也不知道,则这是可以使用如下命令: find / -name httpd.conf ...