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 ...
随机推荐
- java 线程的使用
java 线程的使用 //线程的使用 //需要记三个单词 //1.Thread 线程的类名 //2. Runnable 线程的接口 //3. start 执行线程 //使用继承线程类的方式实现线程 c ...
- Java中的枚举
枚举通过enum关键字进行定义.实际上当定义一个枚举类型的时候,该类型默认继承了Enum类. 枚举的定义格式如下: enum Color { RED,BLUE,GREEN; } 下面演示一个枚举变量的 ...
- JAVA设计模式之合成模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述合成(Composite)模式的: 合成模式属于对象的结构模式,有时又叫做“部分——整体”模式.合成模式将对象组织到树结构中,可以用来描述 ...
- 10.11 安装pod
原文地址:http://www.jianshu.com/p/5fc15906c53a 感谢. 更新升级10.11 cocoapods安装出问题最简单的解决方法 这是因为10.11把cocoapods ...
- Angularjs-Dirty Checking
Angularjs实现了数据双向绑定,就像下面这样: <!doctype html> <htnl ng-app> <head> <script src=&qu ...
- PHP常见方法
1.获取字符串长度: preg_match_all('/./us', $only, $match); echo count($match[0]); 2.Php除法取整 2.1.round — 对浮点数 ...
- nohup输入密码后继续后台运行
Linux/Unix 是真正的多用户,多任务.Linux 提供了 fg 和bg 命令,让你轻松调度正在运行的任务. 假设你发现前台运行的一个程序需要很长的时间,但是需要干其他的事情,你就可以用 Ctr ...
- (1)as_view() (2)在urls.py里面出现的pk是怎么回事 (3)RetrieveAPIView表示什么
下面的代码都是我从github上下载的源码中摘取的django: https://github.com/django/django 下载命令: git clone https://github.com ...
- 用vector容器代替数组 ——使用数组初始化vector对象
在C++中,我们不能用数组直接初始化另一数组,而只能创建新的数组,然后显式的把原数组的元素逐个复制给新的数组. 按照C语言中的做法: const size_t arry_size=6; int int ...
- hive查看建表语句
查看hive建表语句:show create table tablename; 查看hive表结构:describe tablename; 简写:desc tablename;