Simple use of tablelayout in Android
Add the tablelayout control to layout.
<Tablelayout Android: Id = "@ + ID/mytablelayout" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_marginleft = "40dp" Android: layout_margintop = "157dp"> </tablelayout>
Code
Public class mainactivity extends activity {private final int WC = viewgroup. layoutparams. wrap_content; private final int fp = viewgroup. layoutparams. fill_parent; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); tablelayout mytablelayout = (tablelayout) This. findviewbyid (R. id. mytablelayout); // automatically fills the blank space in all columns. setstretchallcolumns (true); For (INT r = 1; r <10; r ++) {tablerow TR = new tablerow (this); For (INT c = 1; c <5; C ++) {textview TV = new textview (this); TV. settext ("row" + R + "+ column" + C); tr. addview (TV);} mytablelayout. addview (TR, new tablelayout. layoutparams (FP, WC ));}}}