Java Android:当项目被按下时,可扩展列表视图项目按钮被按下
我有一个可扩展的列表,列表项布局中有复选框按钮。我有按钮的状态列表。当用户触摸列表项时,按钮转换为按下状态。当用户松开按钮时,按钮将返回正常状态。我希望按钮不要转换到这种按下状态(用户看起来很奇怪)。列表项的代码如下所示:Java Android:当项目被按下时,可扩展列表视图项目按钮被按下,java,android,Java,Android,我有一个可扩展的列表,列表项布局中有复选框按钮。我有按钮的状态列表。当用户触摸列表项时,按钮转换为按下状态。当用户松开按钮时,按钮将返回正常状态。我希望按钮不要转换到这种按下状态(用户看起来很奇怪)。列表项的代码如下所示: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:lay
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/vote_minus_one"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_above="@+id/marginBottom"
android:layout_marginRight="5dp"
android:layout_marginTop="6dp"
android:layout_toLeftOf="@+id/vote_plus_one"
android:background="@drawable/vote_down_button"
android:button="@null"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
和按钮:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Pressed -->
<item android:state_pressed="true"
android:drawable="@drawable/track_icon_check_green_bg_green" />
<!-- Checked -->
<item android:state_checked="true"
android:drawable="@drawable/track_icon_check_green_bg_green" />
<!-- Disabled -->
<item android:state_enabled="false"
android:drawable="@drawable/track_icon_check_gray_bg_gray" />
<!-- Normal -->
<item android:drawable="@drawable/track_icon_check_green_bg_gray" />
</selector>
有什么想法吗?似乎父视图上的按下被传输到子视图,但我不确定如何防止这种情况。将state_focused=“true”添加到按下的选择器中修复了该问题
<!-- Pressed -->
<item android:state_pressed="true" android:state_focused="true"
android:drawable="@drawable/track_icon_check_green_bg_green" />