Android 布局文件
<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"
tools:context=".AndroidTableLayoutActivity" > <!-- 定义第一个表格,指定第2列允许收缩,第3列允许拉伸 --> <TableLayout
android:id="@+id/tablelayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="2" > <!-- 直接添加按钮,自己占用一行 --> <Button
android:id="@+id/btn01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="独自一行" >
</Button> <TableRow> <Button
android:id="@+id/btn02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通" >
</Button> <Button
android:id="@+id/btn03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="允许被收缩允许被收缩允许被收缩允许被收缩" >
</Button> <Button
android:id="@+id/btn04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="允许被拉伸" >
</Button>
</TableRow>
</TableLayout>
<!-- 定义第2个表格,指定第2列隐藏 --> <TableLayout
android:id="@+id/tablelayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:collapseColumns="1" > <TableRow> <Button
android:id="@+id/btn05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通" >
</Button> <Button
android:id="@+id/btn06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="被隐藏列" >
</Button> <Button
android:id="@+id/btn07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="允许被拉伸" >
</Button>
</TableRow>
</TableLayout>
<!-- 定义第3个表格,指定第2列填满空白--> <TableLayout
android:id="@+id/tablelayout03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
> <TableRow> <Button
android:id="@+id/btn08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通" >
</Button> <Button
android:id="@+id/btn09"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="填满剩余空白" >
</Button>
</TableRow>
</TableLayout>
<!-- 定义第3个表格,指定第2列横跨2列--> <TableLayout
android:id="@+id/tablelayout04"
android:layout_width="match_parent"
android:layout_height="wrap_content"
> <TableRow> <Button
android:id="@+id/btn10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通" >
</Button> <Button
android:id="@+id/btn11"
android:layout_column="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="填满剩余空白" >
</Button>
</TableRow>
</TableLayout>
</LinearLayout>
1、登录
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:stretchColumns="0,3">
<TableRow>
<TextView />
<TextView
android:text="账 号:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
/>
<EditText
android:id="@+id/account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
android:minWidth="220px"/>
<TextView />
</TableRow>
<TableRow android:layout_marginTop="20px">
<TextView />
<TextView
android:text="密 码:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="220px"
android:textSize="24px"
android:inputType="textPassword"/>
<TextView />
</TableRow>
<TableRow android:layout_marginTop="20px">
<TextView />
<Button
android:id="@+id/login"
android:text="登录"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/quit"
android:text="退出"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView />
</TableRow>
</TableLayout>
要点:
android:orientation="vertical"垂直线性布局,"horizontal"水平线性布局
android:gravity="top"(buttom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal)控制布局中控件的对齐方式。如果是没有子控件的控件设置此属性,表示其内容的对齐方式,比如说TextView里面文字的对齐方式;若是有子控件的控件设置此属性,则表示其子控件的对齐方式,gravity如果需要设置多个属性值,需要使用“|”进行组合
android:gravity 与 android:layout_gravity的区别 android:gravity是指定本元素的子元素相对它的对齐方式。 android:layout_gravity是指定本元素相对它的父元素的对齐方式。
android:layout_weight="1"通过设置控件的layout_weight属性以控制各个控件在布局中的相对大小,线性布局会根据该控件layout_weight值与其所处布局中所有控件layout_weight值之和的比值为该控件分配占用的区域。在水平布局的LinearLayout中有两个Button,这两个Button的layout_weight属性值都为1,那么这两个按钮都会被拉伸到整个屏幕宽度的一半。如果layout_weight指为0,控件会按原大小显示,不会被拉伸;对于其余layout_weight属性值大于0的控件,系统将会减去layout_weight属性值为0的控件的宽度或者高度,再用剩余的宽度或高度按相应的比例来分配每一个控件显示的宽度或高度。
例:
布局代码:
<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"
tools:context=".LinearLayoutActivity" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" > <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#aa0000"
android:gravity="center_horizontal|center_vertical"
android:text="第一列"
android:textSize="15sp" >
</Button> <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00aa00"
android:gravity="center_horizontal"
android:text="第二列"
android:textSize="15sp" >
</Button> <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000aa"
android:gravity="center|bottom"
android:text="第三列"
android:textSize="15sp" >
</Button> <Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#aaaa00"
android:gravity="bottom"
android:text="第四列"
android:textSize="15sp" >
</Button>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" > <Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="bottom"
android:text="第1行"
android:textSize="15sp" >
</Button> <Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="bottom"
android:text="第2行"
android:textSize="15sp" >
</Button> <Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="bottom"
android:text="第3行"
android:textSize="15sp" >
</Button> <Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="bottom"
android:text="第4行"
android:textSize="15sp" >
</Button>
</LinearLayout> </LinearLayout>
Android 布局文件的更多相关文章
- Xamarin Android布局文件没有智能提示
Xamarin Android布局文件没有智能提示 在Visual Studio 2015中,Android项目的Main.axml文件没有智能提示,不便于布局文件的编写.解决办法:(1)从Xamar ...
- Android布局文件夹引起的问题
Android 运行到setContentView(R.layout.splash); 总是出现如下的错误: java.lang.RuntimeException: Unable to start a ...
- android 布局文件中xmlns:android="http://schemas.android.com/apk/res/android"
http://blog.163.com/benben_long/blog/static/199458243201411394624170/ xmlns:android="http://sch ...
- android 布局文件中控件ID、name标签属性的命名包含“@”、“.”、“+”等等符号的含义
1. 在项目的根目录有个配置文件“AndroidManifest.xml”,是用来设置Activity的属性的如 <?xml version="1.0" encoding=& ...
- Android布局文件的载入过程分析:Activity.setContentView()源代码分析
大家都知道在Activity的onCreate()中调用Activity.setContent()方法能够载入布局文件以设置该Activity的显示界面.本文将从setContentView()的源代 ...
- Android布局文件layout.xml的一些属性值
第一类:属性值 true或者 false android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 andr ...
- Android布局文件-错误
View requires API level 14 (current min is 8): <?xml version="1.0" encoding="utf-8 ...
- android 布局文件 ScrollView 中的 listView item 显示不全解决方案
import android.content.Context;import android.util.AttributeSet;import android.widget.ListView; /** ...
- 【Android】Android布局文件的一些属性值
第一类:属性值 true或者 false android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 androi ...
随机推荐
- LCD屏背光驱动调试心得---血的教训
开发板:明远智睿MY-IMX6-EK140 内核源码:linux-3.14.52 背光驱动IC:MP3202 调光原理:通过开发板的核心板PWM4引脚控制MP3202的EN脚,输出不同的占空比从而达到 ...
- linux设备驱动的分层设计思想--input子系统及RTC
转自:linux设备驱动的分层设计思想 宋宝华 http://blog.csdn.net/21cnbao/article/details/5615493 1.1 设备驱动核心层和例化 在面向对象的程序 ...
- hdu1535——Invitation Cards
Invitation Cards Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- mysql 5.7 迁移数据方案
从一台服务器迁移至其他服务器,如何选择最短的停服时间方案 方案一.凌晨3点的全备份+停服后一天的大概一天的增备 1. 拷贝前一天的全备份至新的服务器 rsync -auzrP /Data/dbbak/ ...
- (转) 对svn分支合并类型和深度的理解
合并的工作是把主干或者分支上合并范围内的所有改动列出,并对比当前工作副本的内容,由合并者手工修改冲突,然后提交到服务器的相应目录里.如果当前工作副本是主干,则合并的范围是分支上的改动,如果工作副本是分 ...
- UFLDL深度学习笔记 (四)用于分类的深度网络
UFLDL深度学习笔记 (四)用于分类的深度网络 1. 主要思路 本文要讨论的"UFLDL 建立分类用深度网络"基本原理基于前2节的softmax回归和 无监督特征学习,区别在于使 ...
- xmlUtil 解析 创建
http://yangzi09150915.blog.163.com/blog/static/32953487201072911410398/ package com.aibi.cmdc.webSer ...
- 关于IIS上Yii2的Url路由美化
Yii2默认的路由是酱紫的 http://.../admin/web/index.php?r=site/login 心中理想的美化Url应该这样 http://.../admin/web/site/ ...
- c语言的编译和运行流程
C语言源程序经过编译器进行词法分析 语法分析 等过程生成中间语言(object后缀的文件)编译期间会生成一个字符表和静态分配空间(如new static 全局变量)它们所需的内存空间可以计算出来放在链 ...
- FineUIPro中如何支持多语言(全局资源文件和本地资源文件)
一个客户在邮件中问到了FineUIPro的多语言实现问题,其实 FineUIPro 并没有对此做特殊处理,因此直接使用 ASP.NET 原生支持的资源文件就能实现. 下面我们就以FineUIPro的空 ...