如何给评级栏明星安卓之间的间距?

时间:2015-01-07 08:43:05

标签: android ratingbar

您好我使用自定义评级栏和自定义图像。我需要在星星之间提供空间。当我增加最小高度和最大高度时,星形图像保持不变。

   <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 个答案:

答案 0 :(得分:11)

如果您使用Drawable作为星星。根据png图像中的要求,确保您的drawable有一些左边填充。

否则通过代码无效。几天前我遇到了同样的问题。我通过使用左填充图像完成了。希望它能奏效。

答案 1 :(得分:10)

您只需在PNG的左侧和右侧添加一些空白区域即可。

也就是说,增加GIMP中灰色和黄色PNG的宽度(或者你使用的任何图形编辑程序)。
只是画布,没有拉伸星形图标。

相关问题