我有一个XML文件,用于定义列表中行的布局。布局在最外层是LinearLayout。在里面,还有另一个LinearLayout占据了该行的正确的30个倾角。
我有一个drawable set作为外部LinearLayout的背景资源。这用作行的选择器。该行通常是白色的。单击它时,它是绿色的。
我还有一个drawable set作为内部LinearLayout的背景资源,它占据了行的右边30个凹陷。那个drawable看起来像这样:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/light_blue_pressed" />
<item android:state_selected="true"
android:state_pressed="true"
android:drawable="@color/light_blue_pressed" />
<item android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/light_blue" />
<item android:state_selected="false"
android:state_pressed="true"
android:drawable="@color/light_blue_pressed" />
</selector>
我已将OnClickListener添加到此内部LinearLayout,因此,当您单击它时,LinearLayout的颜色将从light_blue更改为light_blue_pressed。
但是,单击该行上的任何其他位置(读取:外部LinearLayout)不应更改内部LinearLayout的颜色,并且确实如此。
我已将android:duplicateParentState
选项添加到内部LinearLayout,其值为false
,问题仍然存在。
<LinearLayout
android:id="@+id/item_warning_level"
android:layout_width="30dip"
android:layout_height="match_parent"
android:background="@drawable/selector_light_blue"
android:duplicateParentState="false" />
有什么想法吗?
答案 0 :(得分:0)
您应该只将选择器设置为内部LinearLayout
,并从ListView
中删除选择器。您可以通过调用listView.setSelector(null)
或xml android:listSelector="@null"