Android first---常见布局
###绝对布局AbsoluteLayout
* android:layout_x="120dp" 在水平方向上偏移120像素
* android:layout_y="54dp" 在垂直方向偏移54
###相对布局RelativeLayout
* 组件默认左对齐、顶部对齐
* 设置组件在指定组件的右边
android:layout_toRightOf="@id/tv1"
* 设置在指定组件的下边
android:layout_below="@id/tv1"
* 设置右对齐父元素
android:layout_alignParentRight="true"
* 设置与指定组件右对齐
android:layout_alignRight="@id/tv1"
###线性布局LinearLayout
* android:orientation="horizontal" 在水平方向上线性布局
* android:orientation="vertical" 在垂直方向上线性布局
* 设置右对齐
android:layout_gravity="right"
* 当竖直布局时,只能左右对齐和水平居中,顶部底部对齐竖直居中无效
* 当水平布局时,只能顶部底部对齐和竖直居中
* 使用match_parent时注意不要把其他组件顶出去
* 线性布局非常重要的一个属性:权重
android:layout_weight="1"
* 权重设置的是按比例分配剩余的空间
###帧布局FrameLayout
* 默认组件都是左对齐和顶部对齐,每个组件相当于一个div
* 可以更改对齐方式 android:layout_gravity="bottom"
* 不能相对于其他组件布局
###表格布局TableLayout
* 每个<TableRow/>节点是一行,它的每一个节点是一列
* 表格布局中的节点可设置宽高无效
* 根节点<TableLayout/>的子节点宽为匹配父元素,高为包裹内容
* <TableRow/>节点的子节点宽为包裹内容,高为包裹内容
* 根节点<TableLayout/>的节点宽为匹配父元素,高位包裹内容
* 以上默认属性无法修改
*根节点中可以设置一下属性,表示让第一列拉伸填满宽度的剩余空间
* android:stretchColumns="1"
案例一(帧布局):
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="240dp"
android:layout_height="240dp"
android:background="#FF0000"
android:layout_gravity="center"
/>
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#00FF00"
android:layout_gravity="center"
/>
<TextView
android:layout_width="160dp"
android:layout_height="160dp"
android:background="#0000FF"
android:layout_gravity="center"
/>
<TextView
android:layout_width="120dp"
android:layout_height="120dp"
android:background="#FFFF00"
android:layout_gravity="center"
/>
<TextView
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#FF00FF"
android:layout_gravity="center"
/>
<TextView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#FFFFFF"
android:layout_gravity="center"
/>
</FrameLayout>
布局结果:
案例二(线性布局);
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
>
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ff0000"
/>
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#ffffff"
/>
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#000000"
/>
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#00ff00"
/>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@android:color/darker_gray"
/>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#000000"
/>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ffcc0000"
/>
</LinearLayout>
</LinearLayout>
事例结果:
案例三 相对布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中间"
android:layout_centerInParent="true"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上边"
android:layout_above="@id/center"
android:layout_alignRight="@id/center"
android:layout_alignLeft="@id/center"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下边"
android:layout_below="@id/center"
android:layout_alignRight="@id/center"
android:layout_alignLeft="@id/center"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左边"
android:layout_toLeftOf="@id/center"
android:layout_alignTop="@id/center"
android:layout_alignBottom="@id/center"
android:layout_alignParentLeft="true"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右边"
android:layout_toRightOf="@id/center"
android:layout_alignTop="@id/center"
android:layout_alignBottom="@id/center"
android:layout_alignParentRight="true"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左上"
android:layout_toLeftOf="@id/center"
android:layout_above="@id/center"
android:layout_alignParentLeft="true"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左下"
android:layout_toLeftOf="@id/center"
android:layout_below="@id/center"
android:layout_alignParentLeft="true"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右上"
android:layout_toRightOf="@id/center"
android:layout_above="@id/center"
android:layout_alignParentRight="true"
/>
<Button
android:id="@+id/above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右下"
android:layout_toRightOf="@id/center"
android:layout_below="@id/center"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
事例结果:
案例四(表格布局):
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1"
>
<TableRow
>
<TextView
android:layout_column="1"
android:text="open"
/>
<TextView
android:gravity="right"
android:text="Ctrl-O"
/>
</TableRow>
<TableRow >
<TextView
android:layout_column="1"
android:text="save"
/>
<TextView
android:gravity="right"
android:text="Ctrl-S"
/>
</TableRow>
<TableRow
>
<TextView
android:text=" "
/>
<TextView
android:text="save AS"
/>
<TextView
android:text="Ctrl-shift-S"
/>
</TableRow>
<TextView
android:layout_height="1dp"
android:background="#000000"
/>
<TableRow
>
<TextView
android:text="X"
/>
<TextView
android:layout_span="2"
android:text="Import"
/>
</TableRow>
<TableRow
>
<TextView
android:text="X"
/>
<TextView
android:text="Export"
/>
<TextView
android:gravity="right"
android:text="Ctrl-E"
/>
</TableRow>
<TextView
android:layout_height="1dp"
android:background="#000000"
/>
<TableRow
>
<TextView
android:layout_column="1"
android:layout_span="2"
android:text="Quit"
/>
</TableRow>
</TableLayout>
事例结果:
Android first---常见布局的更多相关文章
- android开发中常见布局的注意点
常见布局的注意点 线性布局: 必须有一个布局方向 水平或者垂直 在垂直布局中 只有左对齐 右对齐 水平居中生效 在水平布局中 只有顶部对齐 底部对齐 垂直居中生效 权重:组件按比例分配屏幕的剩余部分( ...
- 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)
1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...
- Android 布局学习之——Layout(布局)具体解释二(常见布局和布局參数)
[Android布局学习系列] 1.Android 布局学习之--Layout(布局)具体解释一 2.Android 布局学习之--Layout(布局)具体解释二(常见布局和布局參数) ...
- Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)
[Android布局学习系列] 1.Android 布局学习之——Layout(布局)详解一 2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数) 3.And ...
- Android下常见动画
摘要:Android中常见的的动画有三种:属性动画.补间动画.帧动画. 注.因为前两种内容较多,后补 一.属性动画 二.补间动画 三.帧动画:本质是将一些连贯的图片加载形成连贯的动画效果 1.在Dra ...
- Android组件---四大布局的属性详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4372222.html Android常见布局有下面几种: LinearL ...
- 14.Android之Layout布局学习
Android布局主要有5种,接下来学习总结下. 1) 最常见的线性布局 LinearLayout 线性布局是Android布局中最简单的布局,也是最常用,最实用的布局. android:orient ...
- 二十一、Android上常见度量单位【xdpi、hdpi、mdpi、ldpi】解读
术语和概念 屏幕尺寸 屏幕的物理尺寸,以屏幕的对角线长度作为依据(比如 2.8寸, 3.5寸). 简而言之, Android把所有的屏幕尺寸简化为三大类:大,正常,和小. 程序可以针对这三种尺寸的屏幕 ...
- [置顶] Android系统五大布局详解Layout
我们知道Android系统应用程序一般是由多个Activity组成,而这些Activity以视图的形式展现在我们面前,视图都是由一个一个的组件构成的.组件就是我们常见的Button.TextEdit等 ...
- Android中常见的MVC模式
MVC模式的简要介绍 MVC是三个单词的缩写,分别为: 模型(Model),视图(View)和控制Controller). MVC模式的目的就是实现Web系统的职能分工. Model层实现系统中的业务 ...
随机推荐
- zabbix_agent 步骤
Zabbix server 做好了,只要在安装一个zabbix-agent(监控端就可以啦) groupadd zabbix useradd -g zabbix zabbix 下载一个客户端的安装包: ...
- javascript保留关键字
1.通用保留关键字 break delete function return typeof case do if switch var catch else in this void continue ...
- BizTalk开发系列(七) Hello World2
之前根据BizTalk的订阅原理,使用BizTalk管理控制台创建了第一个应用程序 Hello World.但是由于控制台的开发功能有限,绝大多数的BizTalk程序都是在集成开发环境Visual S ...
- Python的全局变量
应该尽量避免使用全局变量.不同的模块都可以自由的访问全局变量,可能会导致全局变量的不可预知性.对全局变量,如果程序员甲修改了_a的值,程序员乙同时也要使用_a,这时可能导致程序中的错误.这种错误是很难 ...
- Color Space: HSV
HSV(hue,saturation,value)颜色空间的模型对应于圆柱坐标系中的一个圆锥形子集,圆锥的顶面对应于V=1. 它包含RGB模型中的R=1,G=1,B=1 三个面,所代表的颜色较亮.色彩 ...
- Redis和Memcache对比及选择(转载)
- uglifyjs压缩批处理
uglifyjs. 据说是用来压缩JS文件的,据说还能优化JS,据说是基于node的,还据说比Google Closure Compiler更带感. uglifyjs压缩批处理我们不可能每次都打开cm ...
- 无法启动Mysql服务,错误InnoDB: Attempted to open a previously opened tablespace.
2013-08-04 13:48:22 760 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous t ...
- request.querystring和request.form、session的区别
1. request.querystring是用来接收地址里面问号“?”后面的参数的内容, 用get方法读取的 不安全 request.form是用来接收表单递交来的数据 ,是用post方法读取 ...
- JAVA 打出jar包
1.eclipse下导出 jar包:选择项目右键--->Export...----> 选择java下的JAR file---->next--->选择存入路径--->nex ...