简体   繁体   中英

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

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

In one line:

ratingBar.setRating(8 * stepSize);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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