0

私は、リストビューのアイテムが(複雑なレイアウトであっても)問題なくonpressイベント(押された状態と押されなかった状態にするいくつかのアクション)を処理するという事実に慣れています。しかし今、私はLinearLayoutから同じものが欲しいです-とにかくレイアウトを押すと、すべての子孫がonpressイベントを取得するはずです。

これは私のフラグメントレイアウトの一部であり、プレスイベントで強調表示する必要があります。

<LinearLayout
            android:id="@+id/ll_about_fragment_feedback"
            android:gravity="center_vertical"
            android:layout_height="54dp"
            android:background="@drawable/about_item_bkg"
            android:layout_width="match_parent">

        <ImageView
                android:layout_height="wrap_content"
                android:background="@drawable/about_item_feedback_icon"
                android:layout_width="wrap_content"
                android:layout_marginLeft="11dp"/>

        <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/about_fragment_feedback"
                android:layout_marginLeft="14dp"
                android:textSize="16dp"
                android:textColor="@drawable/about_item_textcolor"/>

</LinearLayout>

ルートレイアウトの背景はプレス時に変更されますが、子孫のテキストカラーは変更されません。ルートからイベントを取得していないようです。

それで、あなたは助けることができますか?

更新:LinearLayout ll_about_fragment_feedbackはOnClickListenerをバインドしており、selecrorsにはすべて問題ありません

4

2 に答える 2

1

Selectorを下のすべてのビューに適用する場合は、すべての子ビューLinearLayoutに追加する必要があります。android:duplicateParentState="true"

<LinearLayout
    android:id="@+id/ll_about_fragment_feedback"
    android:layout_width="match_parent"
    android:layout_height="54dp"
    android:background="@drawable/about_item_bkg"
    android:gravity="center_vertical" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="11dp"
        android:background="@drawable/about_item_feedback_icon"
        android:duplicateParentState="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="14dp"
        android:duplicateParentState="true"
        android:text="@string/about_fragment_feedback"
        android:textColor="@drawable/about_item_textcolor"
        android:textSize="16dp" />

</LinearLayout>
于 2012-10-24T23:22:45.937 に答える
0

onClickListenerレイアウトのルートオブジェクト( )にバインドするだけでll_about_fragment_feedback、それだけです。

于 2012-10-24T22:25:31.563 に答える