Refrencing从风格选择绘制结果用空白的ImageButton [英] Refrencing a selector drawable from a style results blank imagebutton

查看:171
本文介绍了Refrencing从风格选择绘制结果用空白的ImageButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个 ImageButtons 改变基于其状态的图像。 (等同于喜欢按钮,在九个gag和Facebook应用程序)。

I want to have a ImageButtons changing the image based on its state. (same as "like" button in nine gag and facebook apps).

我已经定义为他们每个人的风格选择引用作为绘制,但是当我运行程序,图像不会出现。你能告诉我什么是错的这种做法? (对不起我的英语不好)

I have defined a style for each of them that references a selector as a drawable but when I run the program, images doesn't appear. Can you tell me what's wrong with this approach? (sorry for my bad English)

comment_actions_style价值观的文件夹:
    

comment_actions_style in values folder:

    <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>

和像绘制文件夹绘制:(其它按键都一样)

and like drawable in drawable folder: (other buttons are the same)

<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>

编辑:结果
我忘了提,我有一个列表视图,它的项目是用户的意见和评论都上面描述的按钮。


I forgot to mention, I have a list view that its items are user comments and comments have buttons described above.

这是我的项目布局(的一部分)

here is my items layout (part of it)

<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布局:

and comment_actions layout:

<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>

这些按键也从布局继承,如果这就是问题。

These buttons also inherit from a layout if that's matter.

推荐答案

在这里,您正在设置样式comment_actions布局,这是一个相对布局,这将不效以应对你的机器人:src属性

Here, your are setting style for comment_actions layout, and it is a Relative Layout, which won't be abled to response to your "android:src" attribute.

<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>

这篇关于Refrencing从风格选择绘制结果用空白的ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆