I am following the standard example of how to add a RatingBar
. To control the number of stars I tried to use android:numStars="5"
. The problem is that the number of stars doesn't seem to do anything at all. In portrait-layout I get 6 stars and when I flip the phone I get about 10 stars. I tried to set the number of stars in my Activity (myBar.setNumStars(5)
) that loads the xml but there was no success with that option either.
So my question is how do I define my layout so that it will only show five stars? Set numStars
doesn't seem to work.
Thanks in advance, Roland
To show a simple star rating in round figure just use this code
And use it like this
button.setText(getIntToStar(4));
The RatingBar.setNumStar documentation says:
So setting the layout width to wrap_content should solve this problem.
I'm also facing the problem that exceeding the stars than specified no of stars. For this, we don't want worry about whatever the layout type either relative or linear layout. Simply use the width as follows:
Please avoid using match_parent and fill_parent for ratingbar.
Hope the things would be helpful.
If you are using
android:layout_width="match_parent"
Use wrap_content and it will only show the set numStars :)
android:layout_width="wrap_content"
The default value is set with andoid:rating in the xml layout.