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 (一)
结果如下图:
- 大小: 36.1 KB
分享到:
相关推荐
Android入门第五篇之TableLayout (二).docx
Android入门第四篇之TableLayout (一).docx
android 利用TableLayout自动生成表格
TableLayout,实现动态添加和删除行,判断行中的数据是否含有空值,可以手动地输入数据,也可以选择数据添加在表格中,并实现统计表格中的数据。
android中利用tablelayout实现表格效果
看到很多在安桌上做表格的例子,总感觉不太理想,所以自己做了一个,感觉比较好用,供参考。 (图片在哪儿上传?)
Android移动应用开发表格布局TableLayout的特点.pdf 学习资料 复习资料 教学资源
Android移动应用开发表格布局TableLayout的常用属性.pdf 学习资料 复习资料 教学资源
Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。 当为View时,该View将独占一行。 三个...
利用TableLayout自定义可点击表格
Android使用TableLayout动态布局实例: http://blog.csdn.net/lk_blog/article/details/7436380
表格布局的标签是TableLayout,TableLayout继承了LinearLayout。所以它依然是一个线性布局。 前言: 1、TableLayout简介 2、TableLayout行列数的确定 3、TableLayout可设置的属性详解 4、一个包含4个TableLayout布局...
用Android Studio 2.3.3做的表格布局例子,主要用到<TableLayout>、标签,还有android:shrinkColumns="0,1,2"、android:layout_column="0"等设置。
Android开发之动态生成表格及其边框专栏博客频道
NULL 博文链接:https://hanllove001.iteye.com/blog/1185546
本文实例为大家分享了Android表格布局TableLayout的具体代码,供大家参考,具体内容如下 1.TableLayout TableLayout表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象, 当然也可以使一个View的...
android:collapseColumns:将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。 android:stretchColumns:设置指定的列为可伸展的列,以填满剩下的多余空白空间,若有多列需要设置...
本文初步讲述了Android中TableLayout的应用,对Android初学者有一定的学习借鉴价值。具体如下: TableLayout跟TableLayout 是一组搭配使用的布局,TableLayout置底,TableRow在TableLayout的上面,而Button、TextView...
程序源代码下载 博文链接:https://greatwqs.iteye.com/blog/1045709