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 ...
随机推荐
- 有关项目上潜在需要的移动端GIS系统源码整理,待后续更新
GPS Tools For Android 前言: GPS数据在做GIS开发时的一份宝贵的数据,在不侵犯他人隐私的情况下通过互联网的模式收集GPS是成本最为低廉的一种模式. 背景: 现在公司在做一个项 ...
- php二维数组排序方法(转自http://www.3lian.com/edu/2013/12-26/118882.html)
一维数组排序可以使用asort.ksort等一些方法进程排序,相对来说比较简单.二维数组的排序怎么实现呢?使用array_multisort和usort可以实现 例如像下面的数组: 代码如下: ...
- silverlight 鼠标事件处理
托管代码注册鼠标事件 不需要再.xaml中声明注册事件. .xaml <Ellipse Name=" Fill="Orange" Canvas.Top=" ...
- python中getattr函数 hasattr函数
hasattr(object, name)作用:判断对象object是否包含名为name的特性(hasattr是通过调用getattr(ojbect, name)是否抛出异常来实现的).示例: > ...
- 2016-07-15: Window定时器使用
windows下定时器使用实例 #include <iostream> #include <Windows.h> using namespace std; void Timer ...
- javaweb学习第一天 debug
debug 断点: f5:step into f6:step over f7:step return drop to frame:跳到当前方法的的第一行 resume:跳到下一个断点 watch:观察 ...
- Bitmap 的bitmapdata和texture区别
Texture:纹理类是对不同平台不同的图片资源的封装在HTML5中,资源是一个HTMLElement对象在OpenGL / WebGL中,资源是一个提交GPU后获取的纹理idTexture类封装了这 ...
- objective c, category 和 protocol 中添加property
property的本质是实例变量 + getter 和 setter 方法 category和protocol可以添加方法 category 和 protocol中可以添加@property 关键字 ...
- ASP.NET Web API系列教程目录
ASP.NET Web API系列教程目录 Introduction:What's This New Web API?引子:新的Web API是什么? Chapter 1: Getting Start ...
- ABAP-SQL基础知识
SQL语法 我们在编写ABAP4程序的时候,经常需要从TABLE中根据某些条件读取数据,读取数据最常用的方法就是通过SQL语法实现的.ABAP/4中可以利用SQL语法创建或读取TABLE,SQL语法分 ...