Search code examples
androidandroid-layoutratingbar

Rating bar stars don't change


In my code I want set my custom stars but it didn't work properly

 <RatingBar
                android:id="@+id/ratingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:numStars="5"
                android:stepSize="1"
                android:rating="1"
                android:progressDrawable="@drawable/rating_bar_color"/>

rating_bar_color.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background" android:drawable="@drawable/starw30" />
    <item android:id="@android:id/progress" android:drawable="@drawable/star" />
</layer-list>

I use this code and what I got in result

enter image description here

Where the lines is coming from. The stars are the same size as default star size.


Solution

  • These lines comes because you are trying to wrap the Rating Bar image by using android:layout_height="wrap_content". So, as a solution you have to provide the height of the rating bar to the size of the image.

    If the size of the rating bar image is 20, then try adding

    android:layout_height="20dip"

    This will work for you!