ビューのさまざまな状態に対してさまざまなドローアブルを表示するために、Android UI で StateList を使用しています。
コードはこちら。問題は、最初のandroid:background="@drawable/state_list"
LinearLayout を配置すると、「押された」イベントの状態を強調表示するように機能することです。
しかし、同じ StateList を 2 番目の 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>