android - Decrease the size of the radio button icon -
i progrmatically creating radio button, , works fine,
radioimagebutton radioimagebutton = new radioimagebutton(this); radioimagebutton.setgravity(gravity.center); radioimagebutton.setid(buttonid); radioimagebutton.settextcolor(color.black); radioimagebutton.setcompounddrawableswithintrinsicbounds(icon, null,null, null)// use set icon radioimagebutton.setbackgrounddrawable(drawable); radiogroup.layoutparams radioimagebuttonparams = new radiogroup.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent, 1f); radioimagebuttonparams.setmargins(0, 0, 1, 0); radiogroup.addview(radioimagebutton, radioimagebuttonparams);
in radioimagebutton class
drawable image; public radioimagebutton(context context) { super(context); setbuttondrawable(android.r.color.transparent); } @override protected void ondraw(canvas canvas) { super.ondraw(canvas); if (image != null) { image.setstate(getdrawablestate()); final int verticalgravity = getgravity() & gravity.vertical_gravity_mask; final int height = image.getintrinsicheight(); int y = 0; switch (verticalgravity) { case gravity.bottom: y = getheight() - height; break; case gravity.center_vertical: y = (getheight() - height) / 2; break; } int buttonwidth = image.getintrinsicwidth(); int buttonleft = (getwidth() - buttonwidth) / 3; image.setbounds(buttonleft, y, buttonleft + buttonwidth, y + height); image.draw(canvas); } }
but icon being displayed big , need decrease size of icon. have tried setheight
not working.
radioimagebutton.setcompounddrawableswithintrinsicbounds(icon, null,null, null) used set icon
ok fixed myself , here answer
private drawable resize(drawable image) { bitmap b = ((bitmapdrawable)image).getbitmap(); bitmap bitmapresized = bitmap.createscaledbitmap(b, 50, 50, true);// filter attribute set true return new bitmapdrawable(bitmapresized); }
the code above modify size of drawable, , make sure filter attribute set true icons not blur.
hope helps 1 in future. happy coding :)
Comments
Post a Comment