2013-12-12 64 views
1

在我的代碼我希望把我的定製明星,但它並沒有正常工作評級酒吧星不改變

<RatingBar 
       android:id="@+id/ratingBar" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:numStars="5" 
       android:stepSize="1" 
       android:rating="1" 
       android:progressDrawable="@drawable/rating_bar_color"/> 

rating_bar_color.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@android:id/background" android:drawable="@drawable/starw30" /> 
    <item android:id="@android:id/progress" android:drawable="@drawable/star" /> 
</layer-list> 

我使用此代碼和我得到了在結果

enter image description here

在線條的來源。星星的大小與默認的星星大小相同。

回答

4

這些行是因爲您嘗試使用android:layout_height="wrap_content"來包裝評級欄圖像。所以,作爲一種解決方案,您必須將評分欄的高度提供給圖像的大小。

如果等級欄圖像的大小爲20,然後嘗試添加

android:layout_height="20dip"

這會爲你工作!

+0

你救了我的命人:) –

+1

爲什麼這被接受,甚至答案呢?主題是「評級欄星星不改變」,而不是「如何修復垂直線條」。 – Logic1

0

只需嘗試android:layout_height="20sp"或您正在使用的任何恆星大小。

一件事,你需要定義樣式爲您量身定製的評價吧:使用my_ratingbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="foodRatingBar" parent="@android:style/Widget.RatingBar"> 
     <item name="android:progressDrawable">@drawable/rating_bar_color</item> 
     <item name="android:minHeight">36dip</item> 
     <item name="android:maxHeight">36dip</item> 
    </style> 
</resources> 
<!--Where 36dp is the size of image and include progress drawable here. 

應用這種風格到的RatingBar:

例如

<RatingBar 
    ... 
    style="@style/my_ratingbar" /> 
+0

你確定它的'機器人下添加一些透明的空間? AFAIK,其重要的'android:layout_height'! –

+0

哎呀,這是一個錯誤。更正並感謝! –

0

此問題是由於圖像縮放不正確造成的。解決這個問題的方法是遵循比例比例這樣..

ldpi | mdpi | tvdpi | hdpi | xhdpi | xxhdpi | xxxhdpi

0.75 | 1 | 1.33 | 1.5 | 2 | 3 | 4

0

當明星資產的大小與評級欄的大小不一樣時,就會發生這些泄露的星星,而明星資產在星形本身和底部邊界之間沒有透明空間。 由於某些原因,android試圖通過複製資產的最低部分來放大圖像,以便像我在其中一個項目中那樣在資產底部添加一些透明空間。

TL;博士:layout_width`這裏什麼事情:明星資產