自定义评级栏

时间:2014-09-09 10:01:02

标签: android ratingbar

我的评级栏中有三张明星的自定义图像

enter image description here enter image description here enter image description here

图层列表(rating_bar_bronze)

<?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/ic_rating_empty"/>
    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/ic_rating_half_bronze"/>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/ic_rating_full_bronze"/>

</layer-list>

xml中的评分栏

<RatingBar
    android:id="@+id/ratingBarNearby"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvProfileSkill"
    android:layout_toRightOf="@+id/ivProfilePhoto"
    android:clickable="false"
    android:isIndicator="true"
    android:numStars="5"
    android:progressDrawable="@drawable/rating_bar_bronze" />

但我的评级栏始终只显示一颗被裁剪的星星,如下图所示 enter image description here

1 个答案:

答案 0 :(得分:1)

我不知道此时它是否对您有用,但我制作了一个可能对您有帮助的自定义评分栏:SimpleRatingBar

它的特点:

  • 完全正常工作android:layout_width:可以将其设置为wrap_contentmatch_parent或abritary dp。
  • 任意数量的明星。
  • 任意步长。
  • 可以精确控制星星的大小,也可以通过设置最大大小来控制。
  • 正常状态下的可自定义颜色(星形和额定条的边框,填充和背景)。
  • 按下状态下的可自定义颜色(星形和额定条的边框,填充和背景)。
  • 明星之间可定制的尺寸分离。
  • 可自定义的星星边框宽度。
  • 可自定义的星角半径。
  • 允许设置OnRatingBarChangeListener
  • 星星填充可以设置为从左到右或从右到左(RTL语言支持)。
  • 在视图中集成了AnimationBuilder,以动画方式设置评级。

Here is a preview of it

您可以在jcenterMaven Central中找到它。因此,在build.gradle文件中,只需添加依赖项:

compile 'com.iarcuschin:simpleratingbar:0.1.+'

在您的示例中,您可以将其用作:

<com.iarcuschin.simpleratingbar.SimpleRatingBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvProfileSkill"
        android:layout_toRightOf="@+id/ivProfilePhoto"
        android:clickable="false"
        android:isIndicator="true"
        app:srb_numberOfStars="5"
        app:srb_stepSize="0.01"
        app:srb_borderColor="@color/your_bronze_color"
        app:srb_fillColor="@color/your_bronze_color"
        />

不需要额外的xml文件:)

我希望它有用。

相关问题