How to make RatingBar to show five stars How to make RatingBar to show five stars xml xml

How to make RatingBar to show five stars


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


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.


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