2015-01-07 26 views
9

嗨我正在使用自定義圖像自定義評級欄。我需要在星星之間提供空間。當我增加最小高度和最大高度時,星形圖像保持不變。如何給評級欄星星android之間的間距?

<RelativeLayout 
    android:id="@+id/RelativeLayout01" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:padding="5dp"> 

    <TextView 
     android:id="@+id/allreviews" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Rating" 
     android:layout_marginLeft="8dp" 
     android:textSize="14sp" /> 

     <RatingBar 
     android:id="@+id/reviewallrating" 
     style="@style/customRatingBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="3dp" 
     android:layout_toRightOf="@+id/allreviews" 
     android:isIndicator="false" 
     android:numStars="5" 
     android:stepSize="0.1" /> 

    </RelativeLayout> 

風格: @繪製/ star_rating_bar_full 12dip 12dip

star_rating_bar_full.xml: 

    <?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_ratingbar_full_empty" /> 
    <!--  <item android:id="@+android:id/secondaryProgress" 
     android:drawable="@drawable/star_ratingbar_full_empty" /> --> 
     <item android:id="@+android:id/progress" 
     android:drawable="@drawable/star_ratingbar_full_filled" /> 
     </layer-list> 

star_ratingbar_full_empty: 

    <?xml version="1.0" encoding="utf-8"?> 

    <!-- This is the rating bar drawable that is used to 
    show a filled cookie. --> 
    <selector 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:state_pressed="true" 
    android:state_window_focused="true" 
    android:drawable="@drawable/star_gray" /> 

    <item android:state_focused="true" 
    android:state_window_focused="true" 
    android:drawable="@drawable/star_gray" /> 

<item android:state_selected="true" 
    android:state_window_focused="true" 
    android:drawable="@drawable/star_gray"/> 

<item android:drawable="@drawable/star_gray" /> 

</selector> 
star_ratingbar_fullfilled.xml: 

<item android:state_pressed="true" 
    android:state_window_focused="true" 
    android:drawable="@drawable/yellow_star" /> 

    <item android:state_focused="true" 
    android:state_window_focused="true" 
    android:drawable="@drawable/yellow_star" /> 

    <item android:state_selected="true" 
    android:state_window_focused="true" 
    android:drawable="@drawable/yellow_star" /> 

<item android:drawable="@drawable/yellow_star" /> 

我在樣式中使用了style =「?android:attr/ratingBarStyle」,但仍然輸出相同。 enter image description here

+2

您可以簡單地在您的PNG的**左側和右側添加一些空白區域。順便說一下......你想要採取行動的「最小高度和最大高度」是如何與**寬度**相關的? –

+0

好的。我用評分欄寬度作爲match_parent,但它與多個星星,即超過5星和尺寸仍然太小。 – Shadow

+0

不會。有一些溝通問題。 RatingBar的寬度保留爲'wrap_content'。增加** GIMP **(或任何**圖形編輯器**程序)中的灰色和黃色PNG的寬度。只是畫布,沒有拉伸星星。 –

回答

9

您可以簡單地在您的PNG的左側和右側添加一些空白空間。

也就是說,增加GIMP中的灰色和黃色PNG的寬度(或者使用任何圖形編輯器程序)。
只是畫布,沒有拉伸星形圖標。

+2

但是,這不是解決方法嗎? –

+0

呃...爲什麼不呢? –

+0

但是,如果您使用色調顏色,但不是PNG文件? – karate

9

如果您正在使用Drawable作爲星星。確保你的drawable有一些左邊的填充符合你在png圖片中的要求。

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