android touchEvent事件学习
学习网址:http://www.apkbus.com/forum.php?mod=viewthread&tid=44296
2、传递流程
(1) 事件从Activity.dispatchTouchEvent()开始传递,只要没有被停止或拦截,从最上层的View(ViewGroup)开始一直往下(子View)传递。子View可以通过onTouchEvent()对事件进行处理。
(2) 事件由父View(ViewGroup)传递给子View,ViewGroup可以通过onInterceptTouchEvent()对事件做拦截,停止其往下传递。
(3) 如果事件从上往下传递过程中一直没有被停止,且最底层子View没有消费事件,事件会反向往上传递,这时父View(ViewGroup)可以进行消费,如果还是没有被消费的话,最后会到Activity的onTouchEvent()函数。
(4) 如果View没有对ACTION_DOWN进行消费,之后的其他事件不会传递过来。
(5) OnTouchListener优先于onTouchEvent()对事件进行消费。
上面的消费即表示相应函数返回值为true。
下面看个实例:定义了2种状态
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<dk.touch.MyLayout
android:id="@+id/out"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#ff345600"
>
<dk.touch.MyLayout
android:id="@+id/middle"
android:layout_width="200dp"
android:layout_height="200dp"
android:gravity="center"
android:background="#ff885678"
>
<dk.touch.MyLayout
android:id="@+id/center"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff345678"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
>
</dk.touch.MyLayout>
</dk.touch.MyLayout>
</dk.touch.MyLayout>
</LinearLayout>
处理机制效果图:

状态2:都不处理事件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<dk.touch.MyLayout
android:id="@+id/out"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#ff345600"
>
<dk.touch.MyLayout
android:id="@+id/middle"
android:layout_width="200dp"
android:layout_height="200dp"
android:gravity="center"
android:background="#ff885678"
>
<dk.touch.MyLayout
android:id="@+id/center"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff345678"
>
</dk.touch.MyLayout>
</dk.touch.MyLayout>
</dk.touch.MyLayout>
</LinearLayout>
处理机制效果图:

继续学习中
android touchEvent事件学习的更多相关文章
- 【转】Android TouchEvent事件传递机制
Android TouchEvent事件传递机制 事件机制参考地址: http://www.cnblogs.com/sunzn/archive/2013/05/10/3064129.html ht ...
- 一文读懂 Android TouchEvent 事件分发、拦截、处理过程
什么是事件?事件是用户触摸手机屏幕,引起的一系列TouchEvent,包括ACTION_DOWN.ACTION_MOVE.ACTION_UP.ACTION_CANCEL等,这些action组合后变成点 ...
- Android TouchEvent事件传递机制
本文转载自:http://blog.csdn.net/morgan_xww/article/details/9372285 跟touch事件相关的3个方法: public boolean dispat ...
- Android touch事件的派发流程
Android TouchEvent事件传递机制 通俗易懂,能够了解Touch事件派发的基本流程. Android中的dispatchTouchEvent().onInterceptTouchEven ...
- Android Touch事件传递机制具体解释 上
尊重原创:http://blog.csdn.net/yuanzeyao/article/details/37961997 近期总是遇到关于Android Touch事件的问题,如:滑动冲突的问题,曾经 ...
- Android View事件分发-从源码分析
View事件分发-从源码分析 学习自 <Android开发艺术探索> https://blog.csdn.net/qian520ao/article/details/78555397?lo ...
- Android Touch事件传递机制详解 上
最近总是遇到关于Android Touch事件的问题,如:滑动冲突的问题,以前也花时间学习过Android Touch事件的传递机制,可以每次用起来的时候总是忘记了,索性自己总结一下写篇文章避免以后忘 ...
- Android Touch事件传递机制 二:单纯的(伪生命周期)
转载于:http://blog.csdn.net/yuanzeyao/article/details/38025165 在前一篇文章中,我主要讲解了Android源码中的Touch事件的传递过程,现在 ...
- Android touch 事件传递机制
前言: (1)在自定义view的时候经常会遇到事件拦截处理,比如在侧滑菜单的时候,我们希望在侧滑菜单里面有listview控件,但是我们希望既能左右滑动又能上下滑动,这个时候就需要对触摸的touch事 ...
随机推荐
- NOIP2010-普及组复赛模拟试题-第一题-手机
题目背景 Background 现在手机使用越来越广泛了 题目描述 Description 一般的手机的键盘是这样的: 要按出英文字母就必须要按数字键多下.例如要按出 x 就得按 9 两下,第一 ...
- app/desktop/view/index.html 显示授权标识
app/desktop/view/index.html 显示授权标识
- 9.创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它。
package com.hanqi.test; public class Triangle { private double a,b,c; public Triangle(double d,doubl ...
- svn地址如何更改
1.先进入平时放的更新文件的位置 2.然后右键 选中TortoiseSVN中的Relocate修改里面的完了之后输入账号和密码就好了当然你要记得密码和账号
- 学习笔记——访问者模式Visitor
访问者模式,通过Visitor的注入,为Element扩展了方法实现.虽然避免了Element不用修改即可修改,但却破坏了类的封装性,同时,一旦变更就需要增加子类,在子类方法中调用基类方法,然后再使用 ...
- MySQL安装--ubuntu
1. 执行命令: $ apt-get install mysql-server 执行上述命令会自动安装mysql-client,mysql-common等包. 2. 安装过程中会让你给root账号设置 ...
- java web 项目如何部署到互联网中 通过输入域名访问?
https://segmentfault.com/q/1010000000710271
- [code]高精度运算
数组存储整数,模拟手算进行四则运算 阶乘精确值 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #includ ...
- Android编译环境(1) - 编译Native C的模块
Android编译环境本身比较复杂,且不像普通的编译环境:只有顶层目录下才有Makefile文件,而其他的每个component都使用统一标准的Android.mk. Android.mk文件本身是比 ...
- spice up your desktop
https://wiki.gnome.org/Projects/GnomeShell/CheatSheet windows10用了一段时间,回来看着gnome3-shell是那么的恶心,翻来翻去重新整 ...