【问题标题】:How to give spacing between rating bar stars android?如何在评分栏星星android之间给出间距?
【发布时间】:2015-01-07 08:43:05
【问题描述】:

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

   <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>

样式: @drawable/star_rating_bar_full 12浸 12浸

   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" 但输出仍然保持不变。

【问题讨论】:

  • 您可以简单地在 PNG 的 左右 两侧添加一些空白区域。顺便说一句....minimum height and maximum height 与您要操作的 width 有什么关系?
  • 好的。我使用评级栏宽度作为 match_parent 但它与多颗星一起使用,即超过 5 颗星并且尺寸仍然太小。
  • 没有。有一些沟通问题。将 RatingBar 的宽度保留为 wrap_content。在 GIMP(或您使用的任何 图形编辑器 程序)中增加灰色和黄色 PNG 的宽度。只是画布,没有拉伸星星。
  • 非常感谢。解决了我的问题
  • 我将我的 cmets 收集到一个答案中,以便您可以接受它并将该问题从未回答的问题队列中删除。

标签: android ratingbar


【解决方案1】:

您可以简单地在 PNG 的左右两侧添加一些空白区域。

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

【讨论】:

  • 但是如果你使用 tint color 而不是 PNG 文件呢?
  • 你可以试试,可以的。但我走的是快速简便的方法;)
【解决方案2】:

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

否则通过代码它不起作用。几天前,我遇到了同样的问题。我通过使用左侧填充图像完成了。希望它会起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    相关资源
    最近更新 更多