1

私はこのようなレイアウトを持っています

<RelativeLayout
            android:id="@+id/layout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="buttonClick" >

            <ImageView
                android:id="@+id/img1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:background="@drawable/imageView_bg"
                android:focusable="false"
                android:focusableInTouchMode="false" />

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="18dip"
                android:background="@drawable/button_bg"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:gravity="left|center_vertical"
                android:paddingLeft="25dip"
                android:text="TEXT"
                android:textColor="#ffffff"
                android:textSize="20dip" />
        </RelativeLayout>

button_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/btn_pressed" 
        android:state_pressed="true"/>
    <item android:drawable="@drawable/btn_normal"/>

</selector>

imageView_bg.xml

  <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/img_pressed" 
            android:state_pressed="true"/>
        <item android:drawable="@drawable/img_normal"/>

    </selector>

ビュー全体をクリックしたい.ボタンとイメージビューの両方がイメージを押しました。RelativeLayoutをクリックすると、ボタンとイメージビューが押されます。上記のレイアウトを使用すると、ボタンと画像ビューを別々に押すと、押された画像が表示されます。

前もって感謝します

4

1 に答える 1

0

あなたはこれを行うことができます、

Relative layout click doのONイベント、

button.perfomClick()
imagebutton.perfomClick()

それが役に立てば幸い..

于 2013-01-15T05:34:21.723 に答える