package com.sptao.chess;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.*;
import android.util.*;
import android.content.*;
public class MainActivity extends Activity
{
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
int map[][]={{0,0,0,0,0,0,0,0,0,0},//0行
{1,0,0,0,0,0,0,0,0,0},//1
{0,0,0,0,0,0,0,0,0,0},//2
{0,0,0,0,1,0,0,0,0,0},//3
{0,0,0,0,0,0,0,0,0,0},//4
{0,0,0,0,0,0,1,0,0,0},//5
{1,0,0,0,0,0,0,0,0,0},//6
{0,0,0,0,0,0,0,0,0,0},//7
{0,0,0,0,0,0,0,0,0,0}};//8.9
int a = 0;
Button bu []=new Button[100];
//新建TableLayout的实例
TableLayout tableLayout = (TableLayout)findViewById(R.id.mainTableLayout1);
//全部列自动填充空白处
tableLayout.setShrinkAllColumns(true);
//生成10行,9列的表格
for(int row=0;row<10;row++) //行
{
TableRow tableRow=new TableRow(this);
for(int col=0;col<9;col++) //列
{
a++;
switch( map[row][col])
{
case 0:
break;
default:
bu.setTag(col+row);
bu[a].setText("("+col+","+row"));
tableRow.addView(bu[a]);
}
//新建的TableRow添加到TableLayout
tableLayout.addView(tableRow, new TableLayout.LayoutParams(WC, WC));
}
}
}