Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give spacing between rating bar stars android?

Hi I am using custom rating bar with custom images. I need to provide space between stars. When I increase minimum height and maximum height, star image remains same.

   <RelativeLayout
    android:id="@+id/RelativeLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp" 
    android:padding="5dp">

    <TextView
        android:id="@+id/allreviews"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Rating"
        android:layout_marginLeft="8dp"
        android:textSize="14sp" />

        <RatingBar
        android:id="@+id/reviewallrating"
        style="@style/customRatingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="3dp"
        android:layout_toRightOf="@+id/allreviews"
        android:isIndicator="false"
        android:numStars="5"
        android:stepSize="0.1" />

   </RelativeLayout>

styles: @drawable/star_rating_bar_full 12dip 12dip

   star_rating_bar_full.xml:

   <?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_ratingbar_full_empty" />
   <!--     <item android:id="@+android:id/secondaryProgress"
      android:drawable="@drawable/star_ratingbar_full_empty" /> -->
      <item android:id="@+android:id/progress"
      android:drawable="@drawable/star_ratingbar_full_filled" />
      </layer-list>

star_ratingbar_full_empty:

   <?xml version="1.0" encoding="utf-8"?>

  <!-- This is the rating bar drawable that is used to
   show a filled cookie. -->
    <selector
   xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:state_pressed="true"
  android:state_window_focused="true"
  android:drawable="@drawable/star_gray" />

  <item android:state_focused="true"
  android:state_window_focused="true"
  android:drawable="@drawable/star_gray" />

 <item android:state_selected="true"
  android:state_window_focused="true"
  android:drawable="@drawable/star_gray"/>

 <item android:drawable="@drawable/star_gray" />

 </selector>
star_ratingbar_fullfilled.xml:

  <item android:state_pressed="true"
  android:state_window_focused="true"
  android:drawable="@drawable/yellow_star" />

  <item android:state_focused="true"
  android:state_window_focused="true"
  android:drawable="@drawable/yellow_star" />

  <item android:state_selected="true"
  android:state_window_focused="true"
  android:drawable="@drawable/yellow_star" />

<item android:drawable="@drawable/yellow_star" />

I used style="?android:attr/ratingBarStyle" in styles but still output remains same. enter image description here

like image 802
Shadow Avatar asked Jan 07 '15 08:01

Shadow


People also ask

How can I give space between star and rating bar in Android?

You can use Custom SVG and Set Your Separation value By using this class, you can fix Android custom SVG RatingBar and set Drawable End by replacing value(I marked this value as There_You_Can_Set_Your_Value) inside the class.

What is rating bar in Android?

android.widget.RatingBar. A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar.

How do I turn off rating bars?

android:attr/ratingBarStyleSmall" or scaleX/scaleY the click interaction with RatingBar is disabled. This works for me. Hope this helps you!


2 Answers

You could simply add some empty space to the left and right sides of your PNGs.

That is, increase the width of the grey and yellow PNGs in GIMP (or whatever graphic editor program you use).
Just the canvas, without stretching the star icon.

like image 109
Phantômaxx Avatar answered Oct 11 '22 07:10

Phantômaxx


If you are using Drawable for the stars. Make sure your drawable have some left padding according to your requirement in the png image.

Otherwise through code its not working. Some days back I stuck with the same problem. I gone through by using the left padded image. Hope it will work.

like image 35
droidd Avatar answered Oct 11 '22 07:10

droidd