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(
set the android:numStars="5"
and android:layout_width="wrap_content"
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
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.
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.
Try to set max value for your RatingBar
Like Below
<RelativeLayout xmlns: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" >
<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" />
</RelativeLayout>
create an xml file in your layout file and set this as the content
Change your showDialog
function like this
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.***your_xml_name***));
editor.setView(layout);
editor.show();