【问题标题】:Android: Ratingbar stepsize below 0.5Android:Ratingbar 步长小于 0.5
【发布时间】:2017-08-01 19:59:00
【问题描述】:

我在我的代码中添加了一个 RatingBar,它运行良好,除了一件事。我正在尝试将步长设置为 0.1,但它仍然根据默认的 0.5 步长做出反应。我可以轻松地将步长设置为高于 0.5,它会按预期做出反应,但不会更低。

我不知道为什么?我唯一能想到的是 RatingBar 的步长上限为 0.5?对于 RatingBar 最少抽取半颗星,哪一个没有意义?

<android.support.v7.widget.AppCompatRatingBar
    android:theme="@style/RatingBar"
    android:stepSize="0.1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ratingbar"
    android:numStars="5"
    android:rating="0.1"
    style="?android:attr/ratingBarStyleSmall"
    android:layout_below="@+id/title"
    android:layout_centerHorizontal="true" />

上面的代码会显示半颗星。但据我所知,它应该是画了十分之一的星星。

P.S 我尝试以编程方式实现它,但仍然相同。

【问题讨论】:

    标签: android xml ratingbar


    【解决方案1】:

    我通过将 secondaryProgressTint 设置为透明的 #00000000 来解决此问题。

    secondaryProgressTint 填充剩余的已开始星。默认情况下的颜色显然设置为与您的主要 progressTint 相同的颜色,因此如果您不知道会引起很多混乱。

    <android.support.v7.widget.AppCompatRatingBar
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:id="@+id/ratingbar"
               style="?android:attr/ratingBarStyleSmall"
               android:isIndicator="true"
               android:progressTint="@color/Red"
               android:secondaryProgressTint="#00000000"
               android:numStars="5"
               android:rating="3.3"
               android:stepSize="0.1"
               android:layout_below="@+id/title"
               android:layout_centerHorizontal="true"
                />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-16
      • 2014-03-02
      相关资源
      最近更新 更多