`
flyfox1982
  • 浏览: 78990 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Android Layout 之TableLayout

阅读更多

TableLayout 是一种类似表格的布局,这种布局会把包含的元素以行和列进行排列。表格的列数为所有行中的最大列数;每一行可以是一个TableRow布局对象,也可以是普通的View对象,TableRow里面没一个元素占一列;TableLayout总列数由列数最多的那一行决定。
<?xml version="1.0" encoding="utf-8"?>

<TableLayout android:id="@+id/tableLayout1" xmlns:android="http://schemas.android.com/apk/res/android"

             android:layout_width="fill_parent"

             android:layout_height="fill_parent"

             android:stretchColumns="1"

             android:shrinkColumns ="1"> <!-- android:stretchColumns 第二列自动伸展-->

   <TextView android:text="Please fill the form"

             android:layout_span="2"

             android:gravity="center"/><!--元素内容居中对齐-->

   <TableRow>

   <TextView android:text="用户名:"

             android:gravity="right"/>

   <EditText android:id="@+id/username" />

   </TableRow>

   <TableRow >

   <TextView android:text="登录密码"/>

   <EditText android:id= "@+id/password" android:password="true"/>

   </TableRow>

   <TableRow >

   <TextView android:layout_height="2dip"

             android:background="#FF909090"

             android:layout_column = "1"/><!-- 指定显示的列数,这儿是第二列 -->

   </TableRow>

   <TableRow >

   <Button android:id="@+id/cancel" android:text="取消"/>

   <Button android:id="@+id/ok" android:text="登录"

           android:padding="4dip"/><!-- 元素内容与边界之间保留3dip的距离  -->

   </TableRow>

</TableLayout>

效果如下:

 



其中 android:stretchColumns=”1″ 作用是让第二列可以扩展到所有可用空间;下面我们讲一下TableLayout几个重要的属性:

collapseColumns – 设置隐藏那些列,列ID从0开始,多个列的话用”,”分隔
stretchColumns – 设置自动伸展那些列,列ID从0开始,多个列的话用”,”分隔
shrinkColumns -设置自动收缩那些列,列ID从0开始,多个列的话用”,”分隔

可以用”*”来表示所有列,同一列可以同时设置为shrinkable和stretchable。



TableRow本身也是一个Layout,里面的元素会安装水平方向依次排列,如果TableRow的父元素不是TableLayout的话,那么他会表现的像一个LinearLayout。

填写调查赚钱

 

  • 大小: 32.5 KB
0
1
分享到:
评论

相关推荐

    android mars视频代码 Layout Layout _02源码 TableLayout

    www.mars-droid.com/Android开发视频教程 TableLayout代码 源码 mars老师讲课 android 视频源码 Layout_02(在此特别感谢mars的无私奉献,此代码为跟随视频边学边做的)

    android之layout(二)RelativeLayout, TableLayout

    NULL 博文链接:https://hanllove001.iteye.com/blog/1185546

    android的layout布局种类.pdf

    Android Layout 是 Android 应用程序的用户界面布局方式,总共有五种基本布局:LinearLayout、AbsoluteLayout、RelativeLayout、FrameLayout、TableLayout。每种布局都有其特点和应用场景,本文将对每种布局进行详细...

    Android Layout多种使用方法源码演示.rar

    Android Layout多种使用方法源码演示,这个例子中演示了如何使用FrameLayout、如何使用RelativeLayout、如何使用RelativeLayout和LinearLayout以及如何使用TableLayout的例子,都挺实用,平时用的比较多,但是比较...

    android mars视频代码 Layout Layout _04源码 LinearLayout TableLayout嵌套布局

    www.mars-droid.com/Android开发视频教程 LinearLayout TableLayout代码 源码 mars老师讲课 android 视频源码 Layout_04(在此特别感谢mars的无私奉献,此代码为跟随视频边学边做的)

    android的layout布局种类

    LinearLayout 是 Android 中最常用的布局种类之一。它提供了控件水平垂直排列的模型,同时可以通过设置子控件的 weight 布局参数控制各个控件在布局中的相对大小。LinearLayout 有两种排列方式:水平排列...

    android layout demo

    此Demo容合了android 布局的全部例程,并且在TableLayout里增加了Activity之间的数据通信及返回数据的方法。

    Android 表格布局TableLayout示例详解

    一、表格布局 TableLayout 表格布局TableLayout以行列的形式管理子元素,每一行是一个TableRow布局对象,当然也可以...android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:stretchC

    Android实验指导.doc

    了解布局Layout的应用 多种Layout: AbsoluteLayout FrameLayout GridView LinearLayout ListLayout RadioGroup TableLayout ……… 3. 利用布局安排各种控件,设计良好用户界面 "&lt;LinearLayout " "xmlns:android=...

    Android控件大全以及各布局空间的使用方式

    android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;!-- FrameLayout - 层叠式布局。以左上角为起点,将 FrameLayout 内的元素一层覆盖一层地显示 --&gt; &lt;FrameLayout android...

    ANDROID实验报告组件布局.pdf

    width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:text="@string/cancel" android:textStyle="bold"/&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; 2、使用线性布局完成系统主界面 ...

    Android高薪之路:Android程序员面试宝典 李宁

    《Android高薪之路:Android程序员面试宝典》目录: 第1章 Android入门 1 1 关于Android的非技术问题 1 1 1 为什么看好 Android 1 1 2 以前是否从事过Android的工作 做过哪些工作 1 1 3 你做的最复杂的界面是什么 1 ...

    Android学习指南之Layout 布局--千锋培训

    文档介绍了Android学习指南Layout前言,(1) LinearLayout,Android官方LinearLayout Demo,(2) RelativeLayout,官方的RelativeLayout Demo,(3) TableLayout,官方的TableLayout Demo

    【Android Studio代码】表格布局

    用Android Studio 2.3.3做的表格布局例子,主要用到&lt;TableLayout&gt;、标签,还有android:shrinkColumns="0,1,2"、android:layout_column="0"等设置。

    Android Layout 示例

    包括LinearLayout、RelativeLayout、TableLayout、FrameLayout、AbsoluteLayout等常见layout的示例程序

    Android实验指导(1).doc

    了解布局Layout的应用 多种Layout: AbsoluteLayout FrameLayout GridView LinearLayout ListLayout RadioGroup TableLayout ……… 3. 利用布局安排各种控件,设计良好用户界面 "&lt;LinearLayout " "xmlns:android=...

    Android 五种Layout的研究 代码实例版

    Android 五种Layout的研究 代码实例版 有对五种的理解 和代码示例 方便理解 与学习

    Android中UI布局Layout

    线性布局LinearLayout 框架布局FrameLayOut RelativeLayout相对布局 绝对布局AbsoluteLayout TableLayout表格布局

    Android实验二-UI界面开发[文].pdf

    Android提供了多种布局方式,如AbsoluteLayout、FrameLayout、GridView、LinearLayout、ListLayout、RadioGroup、TableLayout等。不同的布局方式适合不同的应用场景。 实验过程 实验过程主要包括新建一个Android...

    Android 布局文件Layout XML属性

    Android有Layout:FrameLayout,LinearLayout,TableLayout,RelativeLayout,AbsoluteLayout。 放入Layout中进行排布的View的XML属性: 几种Layout中Item所共有的XML属性:  (1)layout_width  (2)layout_height  ...

Global site tag (gtag.js) - Google Analytics