我在列表视图中使用以下item.xml
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:duplicateParentState="true">
<TextView
android:id="@+id/title"
android:text="@string/title_placeholder"
style="@style/title" />
<com.myapp.android.view.MyView
android:layout_width="11dp"
android:layout_height="11dp"
android:layout_below="@id/title"
android:duplicateParentState="true"
android:clickable="true" />
</RelativeLayout>
</LinearLayout>
我在两个地方使用duplicateParentState
,我的自定义视图MyView
和包裹RelativeLayout
。不过,当我触摸其中一个列表视图的项目时,我在我的视图中没有收到任何触摸事件的触摸事件。
我在这里缺少什么?
答案 0 :(得分:0)
你可以发布你的onTouch代码吗?
来自android文档的:
onTouch() - 返回一个布尔值来指示你的监听器 消耗这个事件。重要的是这个事件可以有 相互跟随的多个动作。所以,如果你在什么时候返回false 收到了下行动作事件,表示你没有 消耗了这个事件,对后续行动也不感兴趣 从这个事件。因此,您不会被要求进行任何其他操作 在事件中,例如手指手势或最终的向上动作 事件