1

アイコン画像とテキストビューを含むレイアウトがあります。私が欲しいのは、親レイアウトを押しながらアイコン画像の背景を変更することです。セレクター機能を試してみましたが、押されているビューでのみ機能します。アイコン画像を押して選択を適用すると、うまく機能しますが、ユーザーが親レイアウト全体を押している間にアイコン画像を変更したいのです。これは私のレイアウトxmlファイルです

<RelativeLayout
                android:id="@+id/home_edit_profile"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" 
                 >



                <RelativeLayout
                    android:id="@+id/first_row_image_container"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true" 
                    android:layout_marginLeft="20dp">

                    <ImageView
                        android:id="@+id/image_edit_profile"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:duplicateParentState="true"
                        android:src="@drawable/home_page_edit_profile_press" 
                        />
                </RelativeLayout>

                <RelativeLayout

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@+id/first_row_image_container" 
                    android:layout_toLeftOf="@+id/first_row_arrow_container"
                    android:paddingLeft="15dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="false"
                        android:text="Edit Profile"
                        android:textColor="#ffffff"
                        android:duplicateParentState="true"
                        android:textAppearance="?android:attr/textAppearanceLarge" />

                </RelativeLayout>

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/home_page_saparatar_line" 
                    android:layout_alignParentBottom="true"/>

            </RelativeLayout>
4

1 に答える 1

3

// この行を追加する必要がありますandroid:duplicateParentState="true"

アイコンとテキストビューの両方で。

android:duplicateParentState - 
When this attribute is set to true, the view gets its drawable state 
(focused, pressed, etc.) from its direct parent rather than from itself. 
于 2013-02-18T14:42:24.187 に答える