14

次の例のように、左揃えの ImageView と ImageView の右側にある 2 つの TextView を使用して、ボタンのようなコンポーネントを作成しようとしています。

 __________________________
|                          |
| |-----|  Bold Main Text  | 
| |Image|                  |
| |-----|  Small Sub Text  |
|__________________________|

また、標準のボタンがそれに関連付けられた選択可能なリソースで行うように、外側のコンテナーのクリック状態に応じて ImageView を変更したいと考えています。そのため、外側のボックスのどこかをクリックすると、画像の選択可能な状態が変更されます。

Button を使用して、「drawableLeft」プロパティを設定して、Image に関連付けられた 1 行のテキストをボタンとして作成できることはわかっていますが、この戦略を使用すると、1 つのテキスト項目しか作成できないようです。

過去にこのような UI コンポーネントを実装した人はいますか?

ありがとう!

4

1 に答える 1

16

ウィジェットandroid:duplicateParentState="true"に追加できます。また、の親をクリック可能でフォーカス可能ImageViewにする必要があります。ImageView

RelativeLayout次のコードのは、:として機能しますButton

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout:height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true">

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:duplicateParentState="true"
            android:src="@drawable/icon" />
        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/image"
            android:layout_alignTop="@+id/image"
            android:layout_alignWithParentIfMissing="true"
            android:duplicateParentState="true" />
        <TextView
            android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"            
            android:layout_toRightOf="@+id/image"
            android:layout_below="@+id/text1"
            android:layout_alignWithParentIfMissing="true"
            android:duplicateParentState="true" />
    </RelativeLayout>
</LinearLayout>
于 2012-01-11T17:07:27.873 に答える