自定义评分条?

3

我有一个布局。我在其中嵌入了一个自定义评分条:

<RatingBar
            android:id="@id/rate"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5.0dip"
            android:isIndicator="true"
            android:max="5"
            android:numStars="5"
            android:progressDrawable="@drawable/ratebar_theme"
            android:stepSize="0.1" />

它是“ratebar_theme”:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/star_empty_show"/>

    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/star_empty_show"/>

    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/star_filled_show"/>

</layer-list>

两个代码 star_empty_showstar_filled_show 都是项目中 drawable 文件夹中的 .png 文件。这两个代码都没有错误,但在 Graphical layout 标签中我看到了这个:

Failed to parse file E:\...\res\drawable\ratebar_theme.xml

而在 错误日志 中,我看到了以下内容:

  org.xmlpull.v1.XmlPullParserException: Binary XML file line #6: <item> tag requires a 'drawable' attribute or child tag defining a drawable

但是我已经为每个项目添加了drawable属性。你知道为什么会出现这个错误吗?


我不明白你遇到了什么错误。 - Janmejoy
尝试清理项目,然后重新启动Eclipse。 - Talha
@Janmejoy 在运行应用程序之前发生了此错误。 - Student Student
你清理并运行了你的项目吗? - Janmejoy
2个回答

2
简单清理一下你的项目并重新启动eclipse,希望能够解决问题。

0

试试这个...

<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

        <item
            android:id="@+android:id/background"
            android:drawable="@drawable/star_empty_show"/>

        <item
            android:id="@+android:id/secondaryProgress"
            android:drawable="@drawable/star_empty_show"/>

        <item
            android:id="@+android:id/progress"
            android:drawable="@drawable/star_filled_show"/>

    </layer-list>

@StudentStudent,很不错啊,我以为你清理并构建后还是没有解决问题,所以才发帖问的。 - Janmejoy
在每个项目中,您必须从@+android:id中删除“+”符号。 - Student Student

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接