Android背景选择器会对视图外的触摸做出反应

Android背景选择器会对视图外的触摸做出反应,android,android-layout,android-view,Android,Android Layout,Android View,我使用以下布局在屏幕上均匀缩放4个视图: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="ho

我使用以下布局在屏幕上均匀缩放4个视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <include
            android:id="@+id/one"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            layout="@layout/item" />

        <include
            android:id="@+id/two"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            layout="@layout/item" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <include
            android:id="@+id/three"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            layout="@layout/item" />

        <include
            android:id="@+id/four"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            layout="@layout/item" />
    </LinearLayout>

</LinearLayout>

include中使用的item.xml如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp" >

    <RelativeLayout
        android:id="@+id/bg_layout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@drawable/bg_selector" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_margin="8dp"
            android:ellipsize="end"
            android:padding="4dp"
            android:singleLine="true"
            android:text="Headline"
            android:textAppearance="@style/SmallTextBold"
            android:textColor="#ffffff" />
    </RelativeLayout>

</RelativeLayout>

结果如下所示,这正是我所期望的:

问题是,当我触摸其中一个项目/视图时,所有背景都会发生变化,它们都会对触摸一个项目/视图做出反应:

这里有什么问题?这和包含有关吗

编辑:我刚刚用包含的
item.xml
布局的实际内容替换了
s,并为这些布局提供了唯一的ID,但问题仍然存在


编辑2:我把我的项目清理了好几次,都没有用。我继续玩弄布局,但毫无用处。通过GIT将所有内容重置为我开始使用的内容,现在一切正常。很奇怪

代码中的单击管理器很可能指向您包含的每个项目上的相同id


尽量不要使用include或编写自定义视图的代码。

谢谢,但是删除include没有任何帮助:(您是否也更改了每个视图的ID?请告诉我,我对这种奇怪的效果很好奇。我在使用include时看到了很多奇怪的事情,有些问题已经通过清除和重新编译(如果使用eclispe)解决了)该项目!是的,我做了。我还更改了每个布局的id,以保持背景的唯一性。我没有解决方案,请尝试在具有背景的视图中放置一个android:clickable=“true”,您还可以提供背景xml的源代码吗?