界面布局之表格布局TableLayout+TableRow
一、基础知识:
TableLayout置底,TableRow在TableLayout的上面,而Button、TextView等控件就在TableRow之上,
另外,TableLayout之上也可以单独放控件。TableLayout是一个使用复杂的布局,最简单的用法就仅
仅是拖拉控件做出个界面,但实际上,会经常在代码里使用TableLayout,例如做出表格的效果。
Android:collapseColumns:以第0行为序,隐藏指定的列
android:shrinkColumns:以第0行为序,自动延伸指定的列填充可用部分
android:stretchColumns:以第0行为序,尽量把指定的列填充空白部分
二、方案一代码展示:
方案一采用xml布局,在代码中除了显示layout之外,未作任何布局相关的操作。
1."Acticity_06\src\yan\acticity_06\MainActivity.Java"
- package yan.activity_06;
- import android.os.Bundle;
- import android.app.Activity;
- public class MainActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- }
2."Activity_06\res\layout\activity_main.xml"
- <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- tools:context=".MainActivity"
- android:stretchColumns="0" >
- <TableRow>
- <TextView
- android:text="第一行第一列"
- android:background="#aa0000"
- android:padding="3dip" />
- <TextView
- android:text="第一行第二列"
- android:padding="3dip"
- android:gravity="center_horizontal"
- android:background="#00aa00"
- ></TextView>
- <TextView
- android:text="第一行第三列"
- android:gravity="right"
- android:background="#0000aa"
- android:padding="3dip" />
- </TableRow>
- <TableRow>
- <TextView
- android:text="第二行第一列"
- android:padding="3dip" />
- <TextView
- android:text="第二行第二列"
- android:gravity="right"
- android:padding="3dip" />
- </TableRow>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello_world" />
- </TableLayout>
三、方案二代码展示:
方案二采用代码布局,在layout文件中除了显示一个空的TabLayout之外,未作任何其它布局。
1."Acticity_06\src\yan\acticity_06\MainActivity.java"
- package yan.activity_06;
- import android.os.Bundle;
- import android.view.ViewGroup;
- import android.widget.TableLayout;
- import android.widget.TableRow;
- import android.widget.TextView;
- import android.app.Activity;
- public class MainActivity 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.activity_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));
- }
- }
- }
2."Activity_06\res\layout\activity_main.xml"
- <?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>
三、效果展示:
1.方案一:
2.方案二:
参考文章有: http://blog.csdn.net/hellogv/article/details/4523745
http://blog.csdn.net/hellogv/article/details/4522125
本文完整代码下载地址: http://download.csdn.net/detail/ypist/5144652
本文博客源地址:http://blog.csdn.net/ypist
界面布局之表格布局TableLayout+TableRow的更多相关文章
- Android基础_2 Activity线性布局和表格布局
在activity的布局中,线性布局和表格布局是最简单的,这次分别从线性布局,表格布局以及线性布局和表格混合布局做了实验,实验中只需要编写 相应的xml的代码,java代码不需要更改,因为我们这里只是 ...
- WPF的布局-Grid(表格布局)
1. Grid布局就是表格布局 如下图: 2. 使用方法 2.1. 先生成适量的行和列,代码如下: <Grid><!--使用Grid控件--> <Grid.ColumnD ...
- Android布局_表格布局TableLayout
一.TableLayout概述 TableLayout表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象 二.TableLayout的全局属性 1 ...
- Android:控件布局(表格布局)TableLayout
TableLayout继承LinearLayout 实例:用表格布局实现计算机布局>>>>>>>>>>>> 有多少个TableR ...
- Android——布局(线性布局linearLayout,表格布局TableLayout,帧布局FrameLayout)
线性布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...
- android——相对布局,表格布局
1.相对布局 RelativeLayout 又称作相对布局,也是一种非常常用的布局.和LinearLayout 的排列规则不同,RelativeLayout 显得更加随意一些,它可以通过相对定位的方式 ...
- Android -- UI布局管理,相对布局,线性布局,表格布局,绝对布局,帧布局
1. 相对布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...
- Android——excise(用线性布局、表格布局、相对布局做发送邮件界面)
LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...
- Android笔记(十) Android中的布局——表格布局
TableLayout运行我们使用表格的方式来排列控件,它的本质依然是线性布局.表格布局采用行.列的形式来管理控件,TableLayout并不需要明确的声明包含多少行多少列,而是通过添加TableRo ...
随机推荐
- doPost()和doGet()
GET 请求的一些特点: GET 请求会有 cache GET 请求会保留在浏览历史中 GET 请求可以保存到书签 GET 请求不应用于处理敏感数据 GET 请求有长度限制 GET 请求应该只用于获取 ...
- [Spring常见问题]java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
这个问题是因为部署在tomcat下的项目中没有springweb包 但是问题来了,但是我的项目中有呀,maven都引了呀,然后我就懵B啦!看到这个博客我就豁然开朗了:http://my.oschina ...
- 在access中如何创建数据库。你认为数据库在网站开发中所扮演的角色是什么。使用数据库和使用文件,两者的优缺点各是什么。
首先在access里面填写所用的信息,将数据库创建,在导入程序设计里进行完成代码. 首先打开我们的access程序,打开方法是单击开始——所有程序. 所有程序中找到microsoft office文件 ...
- 数据库助手类 DBHelper
using System; using System.Collections.Generic; using System.Text; using System.Configuration; using ...
- 读书笔记 --TCP :传输控制协议(一)
TCP提供一种面向连接的,可靠的字节流服务. TCP 通过如下方式来提供可靠性: 应用数据被分割成TCP认为最适合发送的数据块. 超时重传机制.TCP发出一个段后,启动一个定时器,等待目的端确认收到这 ...
- Hibernate Spring
原理: 1. 读取并解析配置文件 2. 读取并解析映射信息,创建SessionFactory 3. 打开Sesssion 4. 创建事务 ...
- C# : CEF操作
代码挺差的,仅供学习.参考 class CEFGlueLoader { class CefAppImpl : CefApp { protected override void OnBeforeComm ...
- PostgreSQL的OGG -- bucardo
bucardo是PostgreSQL数据库中实现双向同步的软件,可以实现PostgreSQL数据库的双master的方案,不过bucardo中的同步都是异步的,它是通过触发器记录变化,程序是perl写 ...
- BeanUtils.copyProperties()方法和PropertyUtils.copyProperties()的区别
首先两者来源于同一个包: import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.Prop ...
- Prince2七大主题之风险
Prince2七大主题之风险 我们前几个节学习了PRINCE2七大主题的商业论证.组织.质量和计划,今天我们开展对于风险模块的讲解. 风险:目的是识别.评估和控制不确定性,从而提高项目的成功率.P ...