android - Spacing between the stars of a rating bar? -
ho can set spacing beween stars? thats ratingbar:
ratingbar = (ratingbar) inflater.inflate(r.layout.ratingbar, null); ratingbar.setlayoutparams(new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content));
the layout:
<?xml version="1.0" encoding="utf-8"?> <ratingbar xmlns:android="http://schemas.android.com/apk/res/android" style="@style/mystyle" android:layout_alignparentright="true" android:layout_height="19dp" android:layout_width="wrap_content" android:numstars="5"> </ratingbar>
the style:
<style name="mystyle" parent="@android:style/widget.ratingbar"> <item name="android:progressdrawable">@drawable/android_r2_ratingstar_yellow</item> <item name="android:indeterminatedrawable">@drawable/android_r2_ratingstar_grey</item> </style>
thanks, cheers
you have add padding png itself. while there known inset drawable (http://developer.android.com/guide/topics/resources/drawable-resource.html#inset) wrap drawable into, code 'tileify'-ing (as referred in android source code) doesn't handle case of drawable being inset drawable, , hence doesn't tile image.
here's tilefy method (in progressbar.java, ancestor ratingbar.java: https://gist.github.com/cyanogenmod/android_frameworks_base/blob/gingerbread/core/java/android/widget/progressbar.java)
private drawable tileify(drawable drawable, boolean clip) { if (drawable instanceof layerdrawable) { layerdrawable background = (layerdrawable) drawable; final int n = background.getnumberoflayers(); drawable[] outdrawables = new drawable[n]; (int = 0; < n; i++) { int id = background.getid(i); outdrawables[i] = tileify(background.getdrawable(i), (id == r.id.progress || id == r.id.secondaryprogress)); } layerdrawable newbg = new layerdrawable(outdrawables); (int = 0; < n; i++) { newbg.setid(i, background.getid(i)); } return newbg; } else if (drawable instanceof statelistdrawable) { statelistdrawable in = (statelistdrawable) drawable; statelistdrawable out = new statelistdrawable(); int numstates = in.getstatecount(); (int = 0; < numstates; i++) { out.addstate(in.getstateset(i), tileify(in.getstatedrawable(i), clip)); } return out; } else if (drawable instanceof bitmapdrawable) { final bitmap tilebitmap = ((bitmapdrawable) drawable).getbitmap(); if (msampletile == null) { msampletile = tilebitmap; } final shapedrawable shapedrawable = new shapedrawable(getdrawableshape()); final bitmapshader bitmapshader = new bitmapshader(tilebitmap, shader.tilemode.repeat, shader.tilemode.clamp); shapedrawable.getpaint().setshader(bitmapshader); return (clip) ? new clipdrawable(shapedrawable, gravity.left, clipdrawable.horizontal) : shapedrawable; } return drawable; }
Comments
Post a Comment