I\'ve added a RatingBar in a layout:
After a lot of research I found the best solution to reduce the size of custom rating bars is to get the size of progress drawable in certain sizes as mentioned below :
xxhdpi - 48*48 px
xhdpi - 36*36 px
hdpi - 24*24 px
And in style put the minheight and maxheight as 16 dp for all Resolution.
Let me know if this doesn't help you to get a best small size rating bars as these sizes I found very compatible and equivalent to ratingbar.small style attribute.
How to glue the code given here ...
Step-1. You need your own rating stars in res/drawable
...
Step-2 In res/drawable
you need ratingstars.xml
as follow ...
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/star_empty" />
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/star_empty" />
<item android:id="@android:id/progress"
android:drawable="@drawable/star" />
</layer-list>
Step-3 In res/values
you need styles.xml
as follow ...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/ratingstars</item>
<item name="android:minHeight">22dip</item>
<item name="android:maxHeight">22dip</item>
</style>
</resources>
Step-4 In your layout ...
<RatingBar
android:id="@+id/rtbProductRating"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:numStars="5"
android:rating="3.5"
android:isIndicator="false"
style="@style/foodRatingBar"
/>
I solve this issue the following: style="?android:attr/ratingBarStyleSmall"
There is no need to add a listener to the ?android:attr/ratingBarStyleSmall
. Just add
android:isIndicator=false
and it will capture click events, e.g.
<RatingBar
android:id="@+id/myRatingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:isIndicator="false" />
<RatingBar
android:rating="3.5"
android:stepSize="0.5"
android:numStars="5"
style = "?android:attr/ratingBarStyleSmall"
android:theme="@style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
// if you want to style
<style name="RatingBar" parent="Theme.AppCompat">
<item name="colorControlNormal">@color/colorPrimary</item>
<item name="colorControlActivated">@color/colorAccent</item>
</style>
// add these line for small rating bar
style = "?android:attr/ratingBarStyleSmall"
<RatingBar
android:id="@+id/ratingBar1"
android:numStars="5"
android:stepSize=".5"
android:rating="3.5"
style="@android:style/Widget.DeviceDefault.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />