I'm working on an app that needs to create a non editable small style rating bar with 4 stars dynamically.
When I call setRating(4)
it shows 4 stars without any problem.
But when I call setRating(3)
it shows 3 and half stars.
setRating(2)
shows 2 stars correctly,
but setrating(1)
shows 1 and half stars.
When I use a normal rating bar in another activity it works fine, but when I use the small style non editable rating bar it doesn't work properly.
Does this have anything to do with the api level or small style non editable rating bar?
Initialization is done like this:
RatingBar ioRatingBar = new RatingBar(this,null,android.R.attr.ratingBarStyleSmall);
ioRatingBar.setNumStars(4);
ioRatingBar.setRating(3);
You can create custom material rating bar by defining drawable xml using material icon of your choice and then applying custom drawable to rating bar using progressDrawable attribute. Below drawable xml uses thumbs up icon for rating bar. Show activity on this post.
star_empty and star are the images which are in your drawable directory. So, you can change star and star_empty in a graphic editor and add a spassing if you need. By adding inset in left and/or right of the drawable, we get unwanted padding on left and/or right border of the View.
You need to set the step size of the RatingBar
like this
ratingBar.setStepSize(1.0);
and also try to define the max rating as:
ratingBar.setMax(4);
If exist padding
, remove. I suggest replace with margin
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With