2015-06-01 112 views
3

我有一個評價吧這樣一個形象:添加保證金/填充到的RatingBar

enter image description here

現在,我想知道我將如何在保證金/填充添加到每個項目評分欄?

styles.xml

<resources> 
<style name="starRatingBar" parent="@android:style/Widget.RatingBar"> 
    <item name="android:progressDrawable">@layout/starratingbar_full</item> 
    <item name="android:minHeight">19dp</item> 
    <item name="android:maxHeight">19dp</item> 
</style> 
</resources> 

starratingbar_full.xml

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

<item android:id="@+android:id/background" 
    android:drawable="@drawable/starunselected" 
    /> 
<item android:id="@+android:id/secondaryProgress" 
    android:drawable="@drawable/starunselected" /> 
<item android:id="@+android:id/progress" 
    android:drawable="@drawable/starselected" /> 
</layer-list> 

activity.xml

<RatingBar 
style="@style/starRatingBar" 
android:numStars="5" 
android:layout_width="100dp" 
android:layout_height="wrap_content" 
android:id="@+id/ratingBar" 
android:layout_marginLeft="130dp" 
android:layout_marginTop="88dp" 
android:stepSize="1"/> 

任何人都可以幫幫我 ?

+0

可能重複的[評級欄星星之間的間距?](http://stackoverflow.com/questions/4213784/spacing-between-the-stars-of-a-rating-bar) – siriscac

回答

3

簡單地使用任何Photoshop或任何編輯器 您可以在您的PNG的左側和右側添加一些空白空間。

2

如果使用可繪製的星星。確保你的drawable有一些左填充符合你的要求。

否則通過代碼它不工作。幾天前,我陷入了同樣的問題。我通過使用左填充圖像經歷了。希望它能起作用。

+0

此答案是沒有鍛鍊你的兄弟? –