RSS

How to make a smaller RatingBar?

09 Feb

How to glue the code given here 

Step-1. You need your own rating stars in res/drawable …

A full star

Half star

Empty star

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"    
/>  

Referenced by: http://stackoverflow.com/questions/2874537/how-to-make-a-smaller-ratingbar

Advertisements
 
2 Comments

Posted by on February 9, 2012 in Android

 

2 responses to “How to make a smaller RatingBar?

  1. pedrera_j

    May 16, 2012 at 9:21 PM

    Thanks, It is a very useful post. I have found a problem when you use the style from the code with:

    RatingBar ratingBar = new RatingBar(this, null, R.style.ratingBarStyle);

    The ratingBar doesn’t appear http://markmail.org/message/hr27pefwiub422yb.
    I need this, because the ratingbar alongs to a item list. Is there some alternative way?

     
  2. pedrera_j

    May 16, 2012 at 9:21 PM

    Sorry, I wanted to say “the ratingbar belongs to a item list”

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: