今天学习了几种Layout。
FrameLayout
FrameLayout是最简单的一个布局对象。它被定制为你屏幕上的一个空白备用区域,之后你可以在其中填充一个单一对象 — 比如,一张你要发布的图片。所有的子元素将会固定在屏幕的左上角;你不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后一个子元素是透明的)。
LinearLayout
LinearLayout以你为它设置的垂直或水平的属性值,来排列所有的子元素。所有的子元素都被堆放在其它元素之后,因此一个垂直列表的每一行只会有一个元素,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高子元素的高度加上边框高度)。 LinearLayout保持子元素之间的间隔以及互相对齐(相对一个元素的右对齐、中间对齐或者左对齐)。
TableLayout
TableLayout将子元素的位置分配到行或列中。android的一个 TableLayout由许多的TableRow组成,每个TableRow都会定义一个row。 TableLayout容器不会显示row、cloumns或cell的边框线。每个row拥有0个或多个的cell;每个cell拥有一个 View对象。表格由列和行组成许多的单元格。表格允许单元格为空。单元格不能跨列,这与HTML中的不一样。
AbsoluteLayout
AbsoluteLayout可以让子元素指定准确的x/y坐标值,并显示在屏幕上。(0, 0)为左上角,当向下或向右移动时,坐标值将变大。AbsoluteLayout没有页边框,允许元素之间互相重叠(尽管不推荐)。我们通常不推荐使用AbsoluteLayout,除非你有正当理由要使用它,因为它使界面代码太过刚性,以至于在不同的设备上可能不能很好地工作。
RelativeLayout
RelativeLayout允许子元素指定他们相对于其它元素或父元素的位置(通过ID指定)。因此,你可以以右对齐,或上下,或置于屏幕中央的形式来排列两个元素。元素按顺序排列,因此如果第一个元素在屏幕的中央,那么相对于这个元素的其它元素将以屏幕中央的相对位置来排列。如果使用XML来指定这个layout,在你定义它之前,被关联的元素必须定义。
用TableLayout实现了一个登录页面
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/darkgray"
android:stretchColumns="1"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="2dip"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号 "
android:textColor="@color/black"
android:layout_margin="2dip"
/>
<EditText
android:id="@+id/name_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_margin="2dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="2dip"
>
<TextView
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码"
android:textColor="@color/black"
android:layout_margin="2dip"
/>
<EditText
android:id="@+id/pwd_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:password="true"
android:layout_margin="2dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="2dip"
>
<TextView android:layout_margin="2dip" />
<CheckBox
android:id="@+id/cb_keep_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码"
android:textColor="@color/black"
android:layout_margin="2dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="2dip"
>
<TextView android:layout_margin="2dip" />
<Button
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="登录"
android:textColor="@color/black"
android:layout_margin="2dip"
/>
</TableRow>
</TableLayout>
显示如下图
- 大小: 49.8 KB
分享到:
相关推荐
layout入门必备,具体讲解行业标准工具virtuoso工具layout工作环境
pads 2007 layout pdf 教程,对于初学者来说学习layout有很大帮助。有需要的来下载。如没积分可联系我
微信小程序源码 FlexLayout布局(学习版)微信小程序源码 FlexLayout布局(学习版)微信小程序源码 FlexLayout布局(学习版)微信小程序源码 FlexLayout布局(学习版)微信小程序源码 FlexLayout布局(学习版)微信小程序源码 ...
altuim designer layout 学习资料。altuim 官方学习资料
全志---音频Layout设计规范。分为:音频原理图,元器件布局,PCB走线,这3个部分介绍,学习音频必备!
写的很好很详细清晰的一份关于hfss 3d layout的教程,非常适合学习上手,欢迎下载,大家一起交流,加油
HFSS 3D Layout用户手册v1.1.pdf,中文手册,概述、界面、模型导入与修改、边界条件与端口激励。
view-measrue/layout学习
智能手机layout guide,很不错的学习资料
七步带你学习电源板Layout的注意点docx,一个电源工程师总结的电源板Layout一些主要注意的地方,主要是从下面这几个地方考虑:
PADS Layout创建Decal是适用于初学者用于学习pads logic的教程
Power Supply PCB Layout&Output Capacitor Design,PCB布局,值得学习; Power Supply PCB Layout&Output Capacitor Design,PCB布局,值得学习;
PCB LAYOUT地线的分析,分析不错....值得学习..
PCB Layout设计规范内容,一共131条规划,分期为您讲解,下面一起来学习一下
QT软件学习记录
LAYOUT 电源地布线概念总结,对于接地概念,模拟走线比较模糊的可以参考学习。
推荐给layout新手学习,有一些skill的脚本实例,还有常用的 Editer方法
IC layout 英文版 适于有一定基础的微电子行业学习
FPC LAYOUT 规范,希望对大家有用,资源共享,一起学习!