Android RatingBar showing more than 5 stars

后端 未结 5 1053
鱼传尺愫
鱼传尺愫 2021-02-12 19:04

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(

相关标签:
5条回答
  • 2021-02-12 19:15

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

    0 讨论(0)
  • 2021-02-12 19:21

    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

    0 讨论(0)
  • 2021-02-12 19:24

    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.

    0 讨论(0)
  • 2021-02-12 19:32

    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.

    0 讨论(0)
  • 2021-02-12 19:34

    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();
    
    0 讨论(0)
提交回复
热议问题