简体   繁体   English

RatingBar更改星级价值评分值得

[英]RatingBar change star value rating worth

I am using the Android SDK RatingBar and trying to do 5 stars where each star is worth the value of 2, but it doesn't work. 我正在使用Android SDK RatingBar并尝试做5星,其中每颗星的价值都为2​​,但它不起作用。 I want the rating "8" to fill only 4 stars, but it fills up all 5. Do I need to use a third-party library to solve this issue? 我希望评级“ 8”仅填充4星,但它填充全部5星。是否需要使用第三方库来解决此问题?

 <RatingBar
      android:id="@+id/user_rating_bar"
      android:isIndicator="true"
      android:rating="8"
      android:stepSize="0.01"
      android:max="10"
      android:numStars="5"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />

I think you can do this way: 我认为您可以这样做:

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stepSize="0.5"
    android:rating="2.5"
    android:numStars="5"
    />

If you use a stepSize value of 0.5 , with 5 stars you have 10 steps to fill, in this way each 0.5 is half a star and a rating of 8 * stepSize will fill only 4 stars instead of 5. 如果您使用stepSize值为0.5 ,有5个星星,则要填充10个步骤,因此,每个0.5都是半颗星星,并且等级8 * stepSize将仅填充4个星星而不是5个星星。

In one line: 一行:

ratingBar.setRating(8 * stepSize);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM