TableLayout添加数据(9宫图也可以用TableLayout做出来 ),本文就是介绍这方面的简单使用方法。

main.xml的代码如下,用到TableLayout的ID为TableLayout01:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<TableLayout
android:id=”@+id/TableLayout01″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”>
</TableLayout>
</LinearLayout>

JAVA代码如下:

package com.LayoutDemo;
import com.LayoutDemo.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class LayoutDemo extends Activity {
/** Called when the activity is first created. */
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP = ViewGroup.LayoutParams.FILL_PARENT;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//新建TableLayout01的实例
TableLayout tableLayout = (TableLayout)findViewById(R.id.TableLayout01);
//全部列自动填充空白处
tableLayout.setStretchAllColumns(true);
//生成10行,8列的表格
for(int row=0;row<10;row++)
{
TableRow tableRow=new TableRow(this);
for(int col=0;col<8;col++)
{
//tv用于显示
TextView tv=new TextView(this);
tv.setText(“(“+col+”,”+row+”)”);
tableRow.addView(tv);
}
//新建的TableRow添加到TableLayout
tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC));
}
}
}
本文来自http://www.boab.cn/index.php/archives/205
http://www.boab.cn/index.php/archives/195 Android入门第五篇之TableLayout (一)
结果如下图:

更多相关文章

  1. Android基于XMPP Smack Openfire开发IM 【二】获取好友列表
  2. Android中ImageButton的运用详解
  3. android 在Google地图上添加标记
  4. Android实现微信和QQ“在其他应用打开”列表中添加自己的应用,并
  5. 打开Android(安卓)PVLogger的方法
  6. 让你的代码减少三倍!使用kotlin开发Android(五) 监听器
  7. JitPack - 发布Android库
  8. Android(安卓)Studio 新建项目的R文件丢失的解决方法
  9. Android----单元测试 (1)

随机推荐

  1. android读写串口
  2. 将 android sql文件放生成在sd卡
  3. android studio 不常见错误-------------
  4. Android(安卓)InstrumentationTestRunner
  5. Android(安卓)onMeasure自定义
  6. Android自动化测试之MonkeyRunner之Monke
  7. Android(安卓)sdk tool android 命令参数
  8. android 触发器
  9. Android(安卓)获取版本号
  10. Android(安卓)-Arouter使用说明