android touch事件无反应,android的touch事件分发响应机制

本文详细介绍了Android中的触摸事件分发和响应机制,从View和ViewGroup的层级结构开始,探讨了touch事件的构成,包括ACTION_DOWN、ACTION_MOVE和ACTION_UP。接着,重点讲解了事件分发的dispatchTouchEvent()、onInterceptTouchEvent()和onTouchEvent()方法,以及事件的分发和拦截流程。通过实例展示了事件如何从Activity到View,再到ViewGroup的传递,并分析了事件响应从子View到父View的回溯过程。
摘要由CSDN通过智能技术生成

想要弄明白android的touch事件分发响应机制需要先充分理解一下几个知识点:

View和ViewGroup

touch事件的构成

ViewGroup如何对事件分发和拦截

View和ViewGroup如何对事件进行响应

View和ViewGroup

先看一下官方文档对view类的部分介绍

View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.

从这里我们就可以看出View是android中所有界面布局组件的基类,而ViewGroup 是View的一个子类,ViewGroup是一个容器类,可以往里面添加子View。

再看一下android的界面是如何构成的

这里有一篇官方文档UI Overview

下面是该文章中的一部分内容:

All user interface elements in an Android app are built using View

and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with. A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface.

Android provides a collection of both View and ViewGroup subclasses that offer you common input controls (such as buttons and text fields) and various layout models (such as a linear or relative layout).

dd68dade9ee7

User Interface Layout

上面的内容大概告诉大家android的界面的布局是一个树状的层级结构。

由顶级的ViewGroup其中包含一个或者多个View和ViewGroup来实现的。

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

android:id="@+id/text"

android:layout_width="wrap_conten

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值