Android 忽略覆盖视图中的接触
我有一个非常简单的布局-它有两个视图:列表视图和完全覆盖的“覆盖”视图;以下是一个例子:Android 忽略覆盖视图中的接触,android,Android,我有一个非常简单的布局-它有两个视图:列表视图和完全覆盖的“覆盖”视图;以下是一个例子: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_hei
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="360dp"
android:layout_height="270dp"
android:id="@+id/imageView"
android:layout_centerInParent="true"
android:background="#8888"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some text"
android:id="@+id/button"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</RelativeLayout>
我使叠加视图比我的视图简单了一点,没有视图需要触摸(也就是说,没有按钮或可滚动区域)-一些线性布局分散了)。我想做的是忽略不仅在布局中,而且在布局的所有子视图中的接触。我想要接收触摸的唯一视图是ListView
我首先以一种简单的方式实现了它——非常类似于上面的方式——触摸永远不会到达底层的ListView(当我拖动时它不会滚动)
我真的不知道如何在Android上实现这一点。另一个SO答案()指向使用一些标志(特别是标志不可触摸和标志不可聚焦),但我不太明白如何使用这些标志。为什么不在xml中为您的RelativeLayout分配一个id,并给它一个OnTouchListener,让它在代码中不做任何事情。这将覆盖没有侦听器的基础视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="360dp"
android:layout_height="270dp"
android:id="@+id/imageView"
android:layout_centerInParent="true"
android:background="#8888"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some text"
android:id="@+id/button"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</RelativeLayout>
为什么不在xml中为RelativeLayout分配一个id,并给它一个OnTouchListener,让它在代码中不做任何事情呢。这将覆盖没有侦听器的基础视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="360dp"
android:layout_height="270dp"
android:id="@+id/imageView"
android:layout_centerInParent="true"
android:background="#8888"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is some text"
android:id="@+id/button"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</RelativeLayout>
我知道这会忽略RelativeLayout和子视图中的接触,但是ListView会得到这些接触吗?这是最终目标。我可以给它一个快速的测试,我想…ListView仍然会收到触摸。谢谢。当基础视图是ListView时,您还需要使用返回false的拖动侦听器
setOnDragListener()
。我知道这将如何忽略RelativeLayout和子视图中的接触,但是ListView会获得这些接触吗?这是最终目标。我可以给它一个快速的测试,我想…ListView仍然会收到触摸。谢谢。当基础视图是ListView时,还需要使用返回false的拖动侦听器setOnDragListener()
。