i'm beginner android developer have skills in c#. have made sliding puzzle c# , want made on android.
this code :
tablelayout layout = new tablelayout(this); setcontentview(layout); layout.setbackgroundcolor(color.gray); final textview text = new textview(this); layout.addview(text); layout.setstretchallcolumns(true); layout.setshrinkallcolumns(true); int rows = 3; final int colomuns = 3; ( int = 0 ; < rows ; ++) { tablerow tr = new tablerow(this); ( int k = 0 ; k < colomuns ; k++) { final int indexk = k+1; final button btn = new button(this); final int indexi = i; final int index = indexi*colomuns+indexk ; btn.setid(index); btn.settextsize(36); btn.setpadding(20, 20, 20, 20); btn.settag(new point(indexi, indexk)); btn.settext(""+ index); //layout params tablerow.layoutparams params = new tablerow.layoutparams(); params.setmargins(5, 5, 5, 5); btn.setlayoutparams(params); //---------------- btn.setbackgroundcolor(color.white); btn.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { tablerow.layoutparams leftviewparams = new tablerow.layoutparams(); leftviewparams.column = 1; btn.setlayoutparams(leftviewparams); point p = (point) btn.gettag(); } }); tr.addview(btn); } layout.addview(tr); }
but, have problem because haven't found "position" property, , want how layout ? , choose tablelayout right ?
thanks,
you should add button layout , offset position using margins/padding, shouldn't positioning based on x,y
use left margin , top margins try , align require.
Comments
Post a Comment