Android: Setting a button size programatically -
i'm trying make 100x100 px button , add gridlayout on position 3,3
button btn = new button(this); btn.setlayoutparams(new viewgroup.layoutparams(100,100)); gridlayout grid4x4 = (gridlayout)findviewbyid(r.id.grid4x4); //i've narrowed down conclusion line problem: grid4x4.addview(btn,new gridlayout.layoutparams(gridlayout.spec(3),gridlayout.spec(3))); //if use: //grid4x4.addview(btn); button size want it, need on //the 3,3 position of grid.
this "almost" works, excepting fact button added bigger 100x100px can see i'm trying fix size want yet reason that's not size get.
in res/values/dimens.xml
add <dimen name="mybuttonsize">100px</dimen>
int size = (int) getresources().getdimension(r.dimen.mybuttonsize);
change code to:
btn.setmaxwidth(size); btn.setmaxheight(size); btn.setlayoutparams(new viewgroup.layoutparams(size,size));
Comments
Post a Comment