Android RatingBar showing more than 5 stars

small rating bar in android
android ratingbar size
ratingbar validation in android
rating bar color android
how to disable rating bar in android
how to set rating bar in android
rating bar click listener android
custom rating bar in android

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(upto 10) in landscape mode and the function setNumStars() has no effect. There are posts already dealing with this issue but they deal with a ratingbar whose laout is defined statically while I am creating it dynamically. How to solve this problem?

public class MainActivity extends Activity {
private Button launchButton;
//Rating dialog
 private AlertDialog.Builder rater;
 private RatingBar ratingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    launchButton =(Button)findViewById(R.id.ratingButton);
    launchButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //Here the alert dialog will be launched
            showRatingDialog();
        }
    });

      //Setting up rating dialog
        rater = new AlertDialog.Builder(this);

        rater.setTitle("This is the rating dialog");


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
public void showRatingDialog()
{
  ratingBar = (RatingBar)findViewById(R.id.ratingStars);
      rater.setNegativeButton("Abbrechen", null);
      rater.setView(ratingBar);
      rater.show();

}
}

I have tried using static layout for the ratingbar but when I do this and try to display the ratingbar via an alert dialog, no stars are shown. Here is the layout file for rating bar:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RatingBar
        android:id="@+id/ratingStars"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1"
        />

</LinearLayout>

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

Android RatingBar showing more than 5 stars, Try to set max value for your RatingBar Like Below <RelativeLayout xmlns:​android="http://schemas.android.com/apk/res/android"  Questions: 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.

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.

Step size in RatingBar, = 1, Ratings = 0, 1, 2, 3, 4, 5, Ratingbar in android. A ratingbar is an extension of progressbar that show rating in stars, to set the ratingbar in android user can use arrow keys, touch or drag using the default android ratingbar size to set android rating.The number of android star rating set in an XML layout when activity layout width is set to wrap content.

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

How can I decrease the size of Ratingbar?, How do I change the rating bar size in Android? Set android:layout_width="wrap_content" and not android:layout_width="0dp" Because if use android:layout_width="0dp" and set android:layout_weight="1" it may show more than 5 stars based on the device width. Update 1 As per your code above if I use this I get all 5 stars only

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

Disable rating on RatingBar, How can I change the color of my rating bar in Android? Android RatingBar with Examples In android, RatingBar is a UI control that is used to get the rating from the user. The RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars and it allows users to set the rating value by touch or click on the stars.

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.

Android Rating bar progress color - Droid By Me, 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  Sometimes rating bar shows more than five stars or sometimes it shows less than five stars. It all depends on the size of the image and also on the size of the rating bar. See the below image Many times, the stars of the rating bar are stretched vertically due to sizing problems as per following image.

Android RatingBar showing more than 5 stars, RatingBar is widget in android that is used to show user rating in the form of stars. The user can drag or touch it to android:isIndicator, setIsIndicator(boolean), If boolean value is true then rating bar act as indicator and user can't change its value. Rating bar is 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22​. Oct 4, 2010. 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.

Android RatingBar Example, A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the​  By default, the number of stars is 5 and the ratingbar step size is 0.5 which means we can leave rating like 0.5, 1.0, 1.5 and so on. The rating is a Float number. We can change the step size and number of stars. It’s just the default behaviour and it is enough in most of the cases. Android RatingBar Example. Let’s start learning with an example.

RatingBar, Learn how we can create custom RatingBar in Android with example in By default a rating bar shows five stars but we can change it using 5. padding: padding attribute is used to set the padding from left, right, top or bottom. then we perform click event on button and display the total number of stars  stars - custom ratingbar android click and determine the number of stars from that. poke around in but I'm a new user and can't post more than 1 URL.

Comments
  • Try to set the step size as 0.1
  • These changes have no effect.
  • When I declared in xml file and set the content its working fine, if you want I can post the code
  • Yes, if its no problem for you
  • I am trying to show the ratingbar via an alert dialog and if I use a static layout as you have mentioned, no ratingbar shows up on alert dialog.Please see the showRatingDialog function
  • It works!But the correct code is: rater.setView(getLayoutInflater().inflate(R.layout.your_rarting_layout_id, null)); Please edit your answer and I will mark it, Thank you!
  • Works perfectly, I don't know why this has no upvotes.