i applying images imagebuttons in code, i'm wondering if there better way shown in example. know it's not correct way can take way time large numbers of views.
btn1.setimageresource(r.drawable.plus); btn2.setimageresource(r.drawable.plus); btn3.setimageresource(r.drawable.plus); btn4.setimageresource(r.drawable.plus); btn5.setimageresource(r.drawable.plus); btn1.setadjustviewbounds(true); btn1.setpadding(0,0,0,0); btn2.setadjustviewbounds(true); btn2.setpadding(0,0,0,0); btn3.setadjustviewbounds(true); btn3.setpadding(0,0,0,0); btn4.setadjustviewbounds(true); btn4.setpadding(0,0,0,0); btn5.setadjustviewbounds(true); btn5.setpadding(0,0,0,0);
you need root view in activity, cast viewgroup
, children, check type , update accordingly. namely follows,
viewgroup rootview = (viewgroup) findviewbyid(android.r.id.content); int children = rootview.getchildcount(); (int = 0; < children; i++) { view view = rootview.getchildat(i); if (view instanceof imagebutton) { ((imagebutton) view).setimageresource(r.drawable.plus); ((imagebutton) view).setadjustviewbounds(true); ((imagebutton) view).setpadding(0,0,0,0); } }
Comments
Post a Comment