0

我对 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"
     />
4

1 回答 1

1

原因:java.lang.NumberFormatException:无法将“res/drawable/ratingbar_yellow.xml”解析为整数

我认为问题是您的ID. 你这样做不正确。

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

它应该是这样的:

android:id="@+id/background"
于 2013-03-26T20:41:56.533 回答