简体   繁体   中英

Showing rating other than specified Step Size on Android Rating Bar

So, I have a basic RatingBar. I want to let the user only rate the page on increments of 1 star, so I did:

ratingBar.setStepSize(1);

and it works.

Now I want to take the average rating and set it to the average of all of the ratings (which may be a non-integer number). If I set the rating like this:

ratingBar.setRating(2.5f);

it rounds it up and displays 3 stars. and Log.d("Rating", Float.toString(ratingBar.getRating())); returns 3.0

If I set `ratingBar.setStepSize(.5);" it works, but I want users to be only able to SET the rating in increments of 1 but be able to DISPLAY increments of .1. Any ideas? Thanks.

You can display a separate dialog in onClick of rating-bar, that contains another rating-bar with stepSize=0.5 .

Or you can set the stepSize of your rating-bar to 0.5 then in onClick event set it to 1 .

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