0

我在 android UI 中使用 StateList 来为视图的不同状态显示不同的可绘制对象。

这是代码。问题是当我android:background="@drawable/state_list"使用第一个 LinearLayout 时,它可以突出显示“按下”事件的状态。

但是,如果我将相同的 StateList 附加到 2nd LinearLayout,它就不起作用。

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="5dp"
    android:background="@drawable/highlight_states">     // this WORKS!

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal"
        android:background="@drawable/highlight_states">    // this DOES NOT WORK.

        <ImageButton
            android:id="@+id/profile_call_button"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:background="@color/transparent"
            android:scaleType="fitCenter"
            android:src="@drawable/icon_phone_green" />
   </LinearLayout>
</LinearLayout>

这是我正在使用的 StateList 的代码。highlight_states.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/selected_textbox" /> <!-- pressed -->
    <item android:state_focused="true" android:drawable="@drawable/highlight_pressed" /> <!-- focused -->    
</selector>
4

1 回答 1

1

在子 LinearLayout 上设置

android:duplicateParentState="true"
于 2013-06-07T07:16:02.670 回答