How to make RatingBar to show five stars

This worked for me: RatingBar should be inside LinearLayout other than having layout width set to wrap content for RatingBar.


The RatingBar.setNumStar documentation says:

Sets the number of stars to show. In order for these to be shown properly, it is recommended the layout width of this widget be wrap content.

So setting the layout width to wrap_content should solve this problem.


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