java - Margin/Padding of the stars in a RatingBar (or position and size)? -
i seek create custom ratingbar application has different image each of 4 stars. next ondraw method works quite on mobile.
public class mybar extends ratingbar { private int[] stararraycolor = { r.drawable.star_1_color, r.drawable.star_2_color, r.drawable.star_3_color, r.drawable.star_4_color }; private int[] stararraygrey = { r.drawable.star_1_grey, r.drawable.star_2_grey, r.drawable.star_3_grey, r.drawable.star_4_grey }; (...) @override protected synchronized void ondraw(canvas canvas) { int stars = getnumstars(); float rating = getrating(); float x = 10; (int i=0;i<stars;i++) { bitmap bitmap; resources res = getresources(); paint paint = new paint(); paint.setantialias(true); paint.setfilterbitmap(true); paint.setdither(true); if ((int) rating-1 == i) { paint.setalpha(255); bitmap = bitmapfactory.decoderesource(res, stararraycolor[i]); } else { paint.setalpha(70); bitmap = bitmapfactory.decoderesource(res, stararraygrey[i]); } bitmap scaled = bitmap.createscaledbitmap(bitmap, 75, 75, true); canvas.drawbitmap(scaled, x, 12, paint); x += 96; } } }
but "calculation" of x/y position , size of images suc*s! trial , error right coordinates...
how can calculate position/size etc. working on every device?
in sources of absseekbar/progressbar have found variables called mpaddingtop, mpaddingbottom etc. there way values?
bitmap has getwidth , getheight function. can utilize calculate size of bitmap. can place them based on (with whatever padding wish use).
java android
No comments:
Post a Comment