Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rating bar showing only half stars instead of full stars

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);
like image 453
akhil Avatar asked Jan 04 '12 13:01

akhil


People also ask

How do I change the rating bar on my Android?

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.

How can I give space between star and rating bar in Android?

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.


2 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);
like image 78
Adil Soomro Avatar answered Oct 12 '22 12:10

Adil Soomro


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

like image 32
Guilherme Avatar answered Oct 12 '22 13:10

Guilherme