2015-08-28 97 views
0

我在我的应用程序中有简单的RatingBar。我设置了numStarts="5",但它显示了更多的5星。当我设置一个ndroid:layout_width="match_parent"我尝试了几个教程,但也没有工作,根据文档numStarts显示开始数,但在我的情况下,它没有工作。我通过doc和几个教程,但没有得到任何解决方案。Android RatingBar numStart不起作用

enter image description here

,但我想只有5分排名吧。

我的评级栏如下。

<RatingBar 
    style="@style/customRatingBar" 
    android:id="@+id/course_rating_bar" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:layout_marginRight="16dp" 
    android:layout_marginLeft="16dp" 
    android:numStars="5" 
    android:isIndicator="false" 
    android:stepSize="1.0"/> 

这是我的自定义样式

<style name="foodRatingBar" parent="@android:style/Widget.RatingBar"> 
     <item name="android:progressDrawable">@drawable/ratingstars</item> 
     <item name="android:minHeight">22dip</item> 
     <item name="android:maxHeight">22dip</item> 
    </style> 

......

<?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" /> 
    <item android:id="@+android:id/secondaryProgress" 
     android:drawable="@drawable/star_empty" /> 
    <item android:id="@+android:id/progress" 
     android:drawable="@drawable/star" /> 
</layer-list> 
+0

你现在是否解决了这个问题? – Zvi

回答

1

你必须设置的android:layout_width = “WRAP_CONTENT”,而不是 “match_parent”。然后你会得到5颗星。