我使用以下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
。尽管如此,当我触摸列表视图的一个项目时,在我注册了一个on touch监听器的视图中,我没有收到任何触摸事件。
我在这里错过了什么?
你可以张贴你的onTouch代码吗?
from android documentation:onTouch() -返回一个布尔值来指示监听器是否消耗此事件。重要的是,这件事可以有多个动作互相跟随。如果你返回false收到down动作事件,表示没有消耗了事件,对后续动作也不感兴趣从这个事件。因此,您不会被要求进行任何其他操作在事件中,比如一个手指的手势,或者最终的向上动作事件