<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="请输入行:"
/> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入数字!"
android:numeric="decimal" /> </LinearLayout> <LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="请输入列:"
/> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入数字!"
android:numeric="decimal"> <requestFocus />
</EditText> </LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="一键自动生成表格"
/> </LinearLayout> </LinearLayout> <TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/table1"> </TableLayout> </LinearLayout>
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends Activity {
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int MP = ViewGroup.LayoutParams.MATCH_PARENT;
private EditText row;
private EditText column;
private Button bt1;
private TableLayout tableLayout; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取控件Button
bt1=(Button) findViewById(R.id.button1);
//获取文本输入框控件
row=(EditText) findViewById(R.id.editText1);
column=(EditText) findViewById(R.id.editText2); //给button按钮绑定单击事件
bt1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
//Color[] colorBlocks= new Color[4096];
//int row_int=Integer.parseInt(row.getText().toString());
//int col_int=Integer.parseInt(column.getText().toString()); //获取控件tableLayout
tableLayout = (TableLayout)findViewById(R.id.table1);
//清除表格所有行
tableLayout.removeAllViews();
//全部列自动填充空白处
tableLayout.setStretchAllColumns(true);
//生成X行,Y列的表格 int theLength = 64; for(int i=0;i<theLength;i++)
{
TableRow tableRow=new TableRow(MainActivity.this);
//生成颜色
for(int j=0;j<theLength;j++)
{
int result = i*theLength +(j+1)-1;//0~4095
int red = result / 256 ;
int green = (result-red*256) / 16;
int blue = result-red*256 - green*16; //tv用于显示
TextView tv=new TextView(MainActivity.this);
//Button bt=new Button(MainActivity.this); tv.setText("-");
tv.setBackgroundColor( Color.rgb(red*16, green*16, blue*16) ); //Color.rgb(red*16-1, green*16-1, blue*16-1)
//tv.setBackgroundResource(35434);
tableRow.addView(tv);
}
//新建的TableRow添加到TableLayout tableLayout.addView(tableRow, new TableLayout.LayoutParams(MP, WC,1));
} }
}); } }

效果呢,博客就不展示了。可以自己试试。黄沙百战穿金甲,不破楼兰终不还

最新文章

  1. Http、Https请求工具类
  2. 通读AFN①--从创建manager到数据解析完毕
  3. SqlServer基础之(触发器)
  4. C#的HTTP开发包 HttpLib
  5. oracle查询出的字段加引号
  6. SNF开发平台WinForm之十四-站内发送系统信息-SNF快速开发平台3.3-Spring.Net.Framework
  7. Nginx入门笔记之————配置文件结构
  8. 20160722noip模拟赛alexandrali
  9. Jetty开发(2)
  10. mongodb学习(三) 安装和基本CRUD
  11. 【原创】1、简单理解微信小程序
  12. &lt;TCP/IP原理&gt; (三) 底层网络技术
  13. 22 pycharm如何将一段代码同时向左缩进一个tab键
  14. 记录前台js判断,如果为空,給议空的占位
  15. python 解码json数据并在一个OrderdDict中保留其顺序
  16. [UE4]爆头和穿墙
  17. Element-UI安装和项目开发
  18. 【C++】自定义比较函数小结
  19. stylus--css 框架使用方法
  20. groovy的三个强劲属性(一)Gpath

热门文章

  1. Linux内核内存管理子系统分析【转】
  2. Linux多节点互信配置
  3. windows+caffe(二)——图片转换为levedb格式
  4. asp.net服务控件的生命周期
  5. html与jsp
  6. python matplotlib 中文显示参数设置
  7. [问题2014S06] 解答
  8. Unity3D之协程(Coroutines &amp; Yield )
  9. java内部类以及匿名类
  10. .NET IL学习笔记(一)