Search code examples
androidxmlandroid-layoutandroid-studioratingbar

Can't change the size of custom RatingBar


I am trying to make custom RatingBar for my android app in which i can change the default size and color of RatingBar. For this purpose i have written styles for CustomRatingBar like this:

<style name="CustomRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/custom_ratingbar</item>
    <item name="android:minHeight">25dp</item>
    <item name="android:maxHeight">25dp</item>
</style>

But the size is not changed rather it shrinks the rating bar like this: enter image description here

Drawable files are : custom_ratingbar.xml, custom_ratingbar_empty, custom_ratingbar_filled

In my xml, RatingBar looks like below:

         <RatingBar
                    android:id="@+id/RatingBar"
                    style="@style/CustomRatingBar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:isIndicator="true"
                    android:numStars="5" />

How can i change the star size of the rating bar without shrinking it?


Solution

  • Try this ,

    custom rating bar style using android’s ratingBar small style.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <style name="CustomRatingBar" parent="@android:style/Widget.RatingBar" >
     <item name="android:numStars">5</item>
     <item name="android:rating">4.5</item>
     <item name="android:stepSize">0.5</item>
     <item name="android:layout_width">wrap_content</item>
     <item name="android:layout_height">wrap_content</item>
     <item name="android:paddingBottom">44dip</item>
     <item name="android:layout_marginLeft">4dip</item>
     <item name="android:layout_marginTop">4dip</item>
    

    Check example. for the same.

    Other solution is :

    Android won't scale a rating bar icons. When you decrease the minHeight and maxHeight android will always crop the icons as shown on the picture. There seems to be the only one solution is to provide your own icons for stars with the desired dimensions and set the minHeight and maxHeight to the size of the icons.