2015-08-28 99 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顆星。