Skip to content Skip to sidebar Skip to footer

Android Ratingbar Showing More Than 5 Stars

I want to show a rating bar via an alert dialog in my android app. The problem I am facing is that depending upon the width of the screen, the ratingbar shows more than 5 stars(upt

Solution 1:

set the android:numStars="5" and android:layout_width="wrap_content"

Solution 2:

setting the width of the RatingBar to "wrap content" solves the whole issue. According to the documentation:

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.

Solution 3:

Try to set max value for your RatingBar Like Below

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/active_bg" ><RatingBarandroid: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" /></RelativeLayout>

create an xml file in your layout file and set this as the content

Change your showDialog function like this

LayoutInflaterinflater= (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
Viewlayout= inflater.inflate(R.layout.***your_xml_name***));
editor.setView(layout);
editor.show();

Solution 4:

keep parent of rating bar as linear layout and keep nothing else in that linear layout, that worked for me

This blog shows the clear picture of solution

Solution 5:

If your RatingBar is in an AlertDialog, stick in inside of a LinearLayout and use setView on the LinearLayout. Then you can set its width to WRAP_CONTENT.

Post a Comment for "Android Ratingbar Showing More Than 5 Stars"