Android开发之TableLayout文本组件…

Android开发之TableLayout文本组件的使用--通过程序动态生成

该种方法,操作复杂,不推荐使用。

直接在我们的src下边的程序当中
public class MainActivity extends Activity {

private String titleData[][]=new String[][]{
{"ID","姓名","EMAIL","地址"},
{"1","包汉青","[email protected]","山东临沂"},
{"2","张三","zhangsan.126.com","中国北京"}
};

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TableLayout layout=new TableLayout(this);
TableLayout.LayoutParams layoutParam=new TableLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
//设置背景
layout.setBackgroundColor(R.drawable.ic_launcher);
for(int i=0;i<this.titleData.length;i++){
    TableRow row=new TableRow(this);
    for(int j=0;j<this.titleData.length;j++){
TextView tx=new TextView(this);
tx.setText(titleData[i][j]);
row.addView(tx,j);
    }
  layout.addView(row);
}
super.setContentView(layout,layoutParam);
   }
}

你可能感兴趣的:(Android开发之TableLayout文本组件…)