简体   繁体   English

Android:可扩展列表视图按下项目时按下项目按钮

[英]Android: Expandable List View Item Buttons Get Pressed When Item Gets Pressed

I have an expandable list, with an list item layout that has check box buttons in it. 我有一个可扩展列表,其中的列表项布局具有复选框按钮。 I have state list drawables for the buttons. 我有按钮的状态列表可绘制对象。 When the user touches the list item, the buttons transition to pressed state. 当用户触摸列表项时,按钮转换为按下状态。 When the user releases the press, the buttons return to normal state. 当用户释放压力时,按钮将返回正常状态。 I'd like the buttons not to transition to this pressed state (it looks weird for the user) The code for the list item looks like: 我希望按钮不过渡到此按下状态(对于用户来说看起来很奇怪)列表项的代码如下:

<?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>

And the button: 和按钮:

<?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>

Any ideas? 有任何想法吗? It seems like the press on the parent view is getting transmitted to the child views, but I'm not sure how to prevent this. 似乎将父视图上的新闻传递到了子视图上,但是我不确定如何防止这种情况。

Adding state_focused="true" to the selector for pressed fixed the issue 将state_focused =“ true”添加到选择器中以解决问题

<!-- Pressed -->
<item android:state_pressed="true" android:state_focused="true"
    android:drawable="@drawable/track_icon_check_green_bg_green" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM