15

私はRelativeLayoutこのようにしています:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/contacts"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="0.2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:contentDescription="@string/content_description_contacts"
    android:scaleType="fitXY"
    android:src="@drawable/contacts" />

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignBottom="@id/image"
    android:paddingBottom="10dp"
    android:textColor="@drawable/text_color"
    android:text="@string/button_contacts"
    android:textSize="12sp" />    
</RelativeLayout>

ここに画像の説明を入力

そして次のようです:

ここに画像の説明を入力

私のcontactsセレクターは次のようです:

<?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/contacts_over" />
<item android:state_selected="true"
    android:drawable="@drawable/contacts_selected" />
<item
     android:drawable="@drawable/contacts_default" />
</selector>

ご覧のとおり、3 つの画像があります。デフォルトでは、選択されて押されています。

しかし、問題があります。デフォルトとstate_selectedイメージのみが期待どおりに機能しますが、機能していstate_pressedないようです。

上記のいくつかがありますがRelativeLayouts、誰も使用していませんstate_pressed

私の問題がどこにあるか誰か知っていますか?

ありがとう!

4

5 に答える 5

38

RelativeLayout がクリック可能であることを確認してください

于 2013-04-23T08:30:07.827 に答える
5

ImageView android:clickable="true" に追加してみてください

于 2013-04-23T08:09:29.617 に答える
2

私の意見Buttonでは、カスタムボタンを作成して配置するのではなく、セレクターを使用して作成する必要RelativeLayoutImageViewありTextViewます。その後、使用できますandroid:drawableTop="@drawable/your_contact_icon"。その後、セレクターが正常に機能するかどうかを確認できます。

于 2013-04-23T08:14:55.120 に答える