0

ImageButtonsその状態に基づいて画像を変更したい。(ナインギャグやフェイスブックアプリの「いいね」ボタンと同じ)。

セレクターをドローアブルとして参照するスタイルをそれぞれに定義しましたが、プログラムを実行すると画像が表示されません。このアプローチの何が問題なのか教えていただけますか? (下手な英語でごめんなさい)

値フォルダー内の comment_actions_style:

    <style name="LikeStyle">
        <item name="android:src">@drawable/like</item>
    </style>

    <style name="DislikeStyle">
        <item name="android:src">@drawable/dislike_normal</item>
    </style>

    <style name="ReplyStyle">
        <item name="android:src">@drawable/reply_normal</item>
    </style>

    <style name="ShareStyle">
        <item name="android:src">@drawable/share</item>
    </style>
</resources>

drawable フォルダー内の drawable のように: (他のボタンは同じです)

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/like_clicked" android:state_pressed="true"/>
 <!-- pressed -->
    <item android:drawable="@drawable/like_focused" android:state_focused="true"/>
 <!-- focused -->
    <item android:drawable="@drawable/like_normal"/>
 <!-- default -->

</selector>

編集:
私は言及するのを忘れていました.私はそのアイテムがユーザーコメントであり、コメントには上記のボタンがあるリストビューを持っています.

これが私のアイテムのレイアウトです(その一部)

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/comment_content"
    android:orientation="horizontal"
    >

    <include
        android:id="@+id/like"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        layout="@layout/comment_actions"
        style="@style/LikeStyle" />
</LinearLayout>

および comment_actions レイアウト:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/comment_action"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="5dip">
        <ImageButton
            android:id="@+id/comment_action_img"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@android:color/transparent"
            />
        <TextView 
            android:id="@+id/comment_action_num"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/comment_action_img"
            android:gravity="center"
            android:layout_marginLeft="5dip"/>

</RelativeLayout>

これらのボタンも、必要に応じてレイアウトから継承します。

4

1 に答える 1

1

ここでは、comment_actions レイアウトのスタイルを設定しています。これは相対レイアウトであり、「android:src」属性に応答できません。

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/comment_content"
android:orientation="horizontal"
>

<include
    android:id="@+id/like"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    layout="@layout/comment_actions"
    style="@style/LikeStyle" /> <!--here,you are setting a style for the RelativeLayout -->
</LinearLayout>
于 2013-07-20T10:19:58.360 に答える