How to make a smaller RatingBar?
Solution 1:
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"
/>
Solution 2:
The default RatingBar widget is sorta' lame.
The source makes reference to style "?android:attr/ratingBarStyleIndicator
" in addition to the "?android:attr/ratingBarStyleSmall
" that you're already familiar with. ratingBarStyleIndicator
is slightly smaller but it's still pretty ugly and the comments note that these styles "don't support interaction".
You're probably better-off rolling your own. There's a decent-looking guide at http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/ showing how to do this. (I haven't done it myself yet, but will be attempting in a day or so.)
Good luck!
p.s. Sorry, was going to post a link to the source for you to poke around in but I'm a new user and can't post more than 1 URL. If you dig your way through the source tree, it's located at frameworks/base/core/java/android/widget/RatingBar.java
Solution 3:
Just use:
android:scaleX="0.5"
android:scaleY="0.5"
Change the scale factor according to your need.
In order to scale without creating a padding on the left also add
android:transformPivotX="0dp"
Solution 4:
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" />
Solution 5:
the small one implement by the OS
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>