为什么自定义样式的评级栏错误膨胀?

时间:2013-03-26 20:37:20

标签: android android-layout

我对ratingBar的自定义样式有问题吗?

03-26 15:22:12.229: E/AndroidRuntime(2075): FATAL EXCEPTION: main
03-26 15:22:12.229: E/AndroidRuntime(2075): android.view.InflateException: Binary XML file line #54: Error inflating class android.widget.RatingBar
03-26 15:22:12.229: E/AndroidRuntime(2075):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
03-26 15:22:12.229: E/AndroidRuntime(2075):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-26 15:22:12.229: E/AndroidRuntime(2075):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
......
03-26 15:22:12.229: E/AndroidRuntime(2075): Caused by: java.lang.NumberFormatException: unable to parse 'res/drawable/ratingbar_yellow.xml' as integer

我的ratingbar_yellow.xml

<item
    android:id="@+android:id/background"
    android:drawable="@drawable/rate_star_small_off"/>
<item
    android:id="@+android:id/secondaryProgress"
    android:drawable="@drawable/rate_star_small_half"/>
<item
    android:id="@+android:id/progress"
    android:drawable="@drawable/rate_star_small_on"/>

我的风格

 <style name="yellowRatingBarSmall" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/ratingbar_yellow</item>
    <item name="android:secondaryProgress">@drawable/ratingbar_yellow</item>
    <item name="android:minHeight">14dip</item>
    <item name="android:maxHeight">14dip</item>
    <item name="android:isIndicator">true</item>
    <item name="android:indeterminateOnly">false</item>
</style>

在我的布局中

<RatingBar
    android:id="@+id/restaurant_rating"
    style="@style/yellowRatingBarSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />

1 个答案:

答案 0 :(得分:1)

  

引起:java.lang.NumberFormatException:无法解析   'res / drawable / ratingbar_yellow.xml'为整数

我认为问题是你ID的声明。你做错了。

android:id="@+android:id/background"

它应该是这样的:

android:id="@+id/background"