How to make a smaller RatingBar?

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

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

Go to res -> values in Android path and create a file is called style.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="hotel_rating_bar_indicator" parent="@android:style/Widget.RatingBar.Indicator" >
    <item name="android:numStars">6</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>
   </style>
   <style name="hotel_rating_bar" parent="@android:style/Widget.RatingBar" >
     <item name="android:numStars">6</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>
   </style>
   <style name="hotel_rating_bar_small" parent="@android:style/Widget.RatingBar.Small" >
     <item name="android:numStars">6</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>
   </style>
</resources>

 

main.xml


 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#000000">

        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="#000000">

                <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:textColor="#ffffff"
                    android:text="Rating Bar"
                    android:paddingLeft="4dp"/>
                <RatingBar 
                    android:id="@+id/hotel_rating_bar"
		    style="@style/hotel_rating_bar" />

                <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:textColor="#ffffff"
                    android:text="Rating Bar Indicator"
                    android:paddingLeft="4dp"/>
                <RatingBar 
                    android:id="@+id/hotel_rating_bar_indicator"
		    style="@style/hotel_rating_bar_indicator" />

              <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:textColor="#ffffff"
                    android:text="Rating Bar Small"
                    android:paddingLeft="4dp"/>
               <RatingBar 
                    android:id="@+id/hotel_rating_bar_small"
		    style="@style/hotel_rating_bar_small" />

       </LinearLayout>
</LinearLayout>

 

 

I get the same result on both (screen capture attached) where I can extend all three styles.

 

If this doesn’t work for you, you might try adding a version identifier to your res/values directory name, like res/values-v6 or res/values-v7. (But here I’m just guessing, based on a bug I’ve seen with images loading from res/drawable.)

 

But I wonder if you might want to upgrade your DROID to Android 2.2 (Froyo) or Android 2.3 (GIngerbread) ?

 

 

 

Copyright © 2011, Motorola Mobility, Inc. All rights reserved unless otherwise explicitly indicated. Sample source code written by Motorola Mobility, Inc. is provided to you under the conditions of the Motorola Modified BSD License (http://developer.motorola.com/docstools/library/bsd-license/).

 

Attachments:
rating-bar-1-50p.jpg