Roland Roland - 5 months ago 29
Android Question

How to make RatingBar to show five stars

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

Answer
<RatingBar
            android:id="@+id/rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/ratingBarStyleSmall"
            android:numStars="5"
            android:stepSize="0.1"
            android:isIndicator="true" />

in code

mRatingBar.setRating(int)
Comments