本文来自http://blog.csdn.net/hellogv/
上一篇文章,主要将如何UI设计器设计TableLayout + TableRow,由于实际应用中,经常需要在代码里往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));
}
}
}
结果如下图:
分享到:
相关推荐
Android入门第五篇之TableLayout (二).docx
Android入门第四篇之TableLayout (一).docx
android 利用TableLayout自动生成表格
Android移动应用开发表格布局TableLayout的常用属性.pdf 学习资料 复习资料 教学资源
Android移动应用开发表格布局TableLayout的特点.pdf 学习资料 复习资料 教学资源
本文初步讲述了Android中TableLayout的应用,对Android初学者有一定的学习借鉴价值。具体如下: TableLayout跟TableLayout 是一组搭配使用的布局,TableLayout置底,TableRow在TableLayout的上面,而Button、TextView...
主要介绍了Android入门之TableLayout应用,需要的朋友可以参考下
Android使用TableLayout动态布局实例: http://blog.csdn.net/lk_blog/article/details/7436380
程序源代码下载 博文链接:https://greatwqs.iteye.com/blog/1045709
NULL 博文链接:https://hanllove001.iteye.com/blog/1185546
TableLayout,实现动态添加和删除行,判断行中的数据是否含有空值,可以手动地输入数据,也可以选择数据添加在表格中,并实现统计表格中的数据。
NULL 博文链接:https://yangguangfu.iteye.com/blog/678977
Android-TableLayout-Example Android-TableLayout-Example
第五讲:用户界面 View(一) FrameLayout, LinearLayout 第六讲:用户界面 View(二) AbsoluteLayout,RelativeLayout 第七讲:用户界面 View(三) TableLayout 第八讲:Intent入门指南 Intent 第九讲:用户...
Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。 当为View时,该View将独占一行。 三个...
看到很多在安桌上做表格的例子,总感觉不太理想,所以自己做了一个,感觉比较好用,供参考。 (图片在哪儿上传?)
第5章 Android中的视图组件 5.1 视图组件 5.1.1 图片视图(ImageView) 5.1.2 滚动视图(ScrollView) 5.1.3 网格视图(GridView) 5.1.4 列表视图(ListView) 5.1.5 切换图片(ImageSwitcher和Gallery) 5.1.6 ...
android中利用tablelayout实现表格效果
•Android---UI篇---Tab Layout(选项卡布局) • •Andorid---UI篇---TableLayout(表格布局) • •Android---UI篇---RelativeLayout(相对布局) • •Android---UI篇---GridView(网格布局) • •Android---UI篇-...