Home » Android » android – Rating bar showing only half stars instead of full stars

android – Rating bar showing only half stars instead of full stars

Posted by: admin June 15, 2020 Leave a comment

Questions:

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);
How to&Answers:

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);

Answer:

If exist padding, remove. I suggest replace with margin.