I need insert a space between the stars of my ratingBar, example the ratingbar is well:
but I need it thus:
how i can do this?
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.
Custom Rating Bar in AndroidCopy your images in the drawable folder and remember image size should be according to the size you want. Step 2. Make XML for the rating bar selector in the drawable folder like below. We made two files, one for the fill or highlighted part and one for the empty or un-highlighted part.
I don't know if it will be useful anymore, but I made a custom library which allows you to change space beetwen stars programatically and in XML (among other stuff): SimpleRatingBar.
It features:
android:layout_width
: it can be set to wrap_content
, match_parent
or abritary dp.Here is a preview of it.
In your case, you would just have to do:
ratingbar.setStarsSeparation(20, Dimension.DP);
or, for example, in pixels:
ratingbar.setStarsSeparation(100, Dimension.PX);
You can find it either in jcenter
or in Maven Central
. So in your build.gradle
file just add to your dependencies:
compile 'com.iarcuschin:simpleratingbar:0.1.+'
You have a next property.
android:progressDrawable = "@drawable/rating_stars" android:indeterminateDrawable = "@drawable/rating_stars"
@drawable/rating_stars :
<?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>
star_empty and star are the images which are in your drawable directory. So, you can change star and star_empty in a graphic editor and add a spassing if you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With