
1. 於是先定義最大的view,並設定為目前佈局:
RelativeLayout r_layout = new RelativeLayout(this);
setContentView(r_layout)
2. 接著定義第二層的TableLayout,並加入到r_layout 裡:
TableLayout tableLayout = new TableLayout(this);
r_layout.addView(tableLayout, new RelativeLayout.LayoutParams(WC, WC));
3. 再定義第三層的TableRow,並加入到tableLayout 裡:
TableRow tableRow1 = new TableRow(this);
tableLayout.addView(tableRow1, new TableLayout.LayoutParams(WC, WC));
4. 最後,定義最小的view,並加入到tableRow裡:
ImageView iv = new ImageView(this);
tableRow1.addView(iv);
如此依序逐步定義,就能順利完成。
本文详细介绍了在Android开发中如何通过定义不同层级的视图来构建复杂的用户界面,从最外层的RelativeLayout开始,逐步深入到内层的TableLayout、TableRow,直至最小单位的ImageView。
1750

被折叠的 条评论
为什么被折叠?



