Android RatingBar showing more than 5 stars
<p>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?</p>

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

}
}
</code></pre>

<p>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:</p>

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

&lt;/LinearLayout&gt;
</code></pre>
