335_ViewGroup
来源:互联网 发布:java 获取temp目录 编辑:程序博客网 时间:2024/05/01 16:56
ViewGroup
阅读郭霖大神笔记
博客地址:http://blog.csdn.net/sinyu890807/article/details/9097463
ViewGroup就是View的集合,包含很多子View或者子ViewGroup,
比如LinearLayout或者RelativeLayout都是ViewGroup
一.ViewGroup事件分发流程
来自定义一个类MyLayout,继承LinearLayout
public class MyLayout extends LinearLayout {
public MyLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
打开主布局文件activity_main,加入自定义MyLayout
<com.example.viewgrouptouchevent.MyLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button2" />
</com.example.viewgrouptouchevent.MyLayout>
然后注册监听事件
myLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("TAG", "myLayout on touch");
return false;
}
});
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("TAG", "You clicked button1");
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("TAG", "You clicked button2");
}
});
分别点击一下Button1、Button2和空白区域
打印结果:
button1,button2,onTouch
说明了点击button的时候,没有执行MyLayout的onTouch,
可以说button的click把事件消费掉了,所以事件不会向下传递
0 0
- 335_ViewGroup
- 336_ViewGroup的dispatchTouchEvent
- Android自定义控件——侧滑菜单_ViewGroup
- ocp-335
- CF-335A-Banana
- CF-335B-Palindrome
- day21,page40,total420+335
- Codeforces Round #335 div2
- leedCode 335 Self Crossing
- [LeetCode 335] Self Crossing
- [leetcode-335]Self Crossing
- Leetcode no. 335
- 335Self Crossing
- 海贼王335在线观看
- 335x按键中断驱动
- AOJ Problem NO.335 三角形
- Codeforces 335A.Magic Spheres
- [leetcode-335]Self Crossing(java)
- CSS3 里添加自定义字体
- 高德地图显示自定义信息窗体
- 334_onTouch和onTouchEvent
- [矩阵快速幂/推函数式]Codeforces185A Plant
- 神奇的程序
- 335_ViewGroup
- 胜利大逃亡hdu1253三维bfs
- LOL因为代理登录失败的问题
- 336_ViewGroup的dispatchTouchEvent
- 如何将span 元素设置成有高度宽度的块元素
- 集合:接口Set
- 红色标重点,蓝色分列表,紫色经验区
- 337_图片轮播器使用button
- Android开发中的动画(下)--属性动画Property Animation