Android的布局方式
1.LinearLayout(线性布局)
android:orientation="vertical" //布局
android:layout_width="wrap_content" //控件宽度
android:layout_height="fill_parent" //控件高度
android:layout_weight //可以指定每个控件所占的比例
注意:"vertical":垂直布局 "horizontal":水平布局
wrap_content:宽度/高度和内容的宽度/高度相同
fill_parent:宽度/高度是整个父组件的宽度和高度
<?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"
>
<TextView
android:id="@+id/ete1"
android:layout_width="100px"
android:layout_height="100px"
android:background="#00FF00"
/>
<TextView
android:id="@+id/bte1"
android:layout_width="80px"
android:layout_height="80px"
android:background="#0000FF"
/>
<TextView
android:id="@+id/tve1"
android:layout_width="60px"
android:layout_height="60px"
android:background="#FF0000"
/>
</LinearLayout>
代码示例
2.FrameLayout(帧布局)
叠加效果
<?xml version="1.0" encoding="utf-8"?>
<!-- "vertical":垂直布局 "horizontal":水平布局 -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="100px"
android:layout_height="100px"
android:background="#FF0000"
/>
<TextView
android:layout_width="80px"
android:layout_height="80px"
android:background="#00FF00"
/>
<TextView
android:layout_width="60px"
android:layout_height="60px"
android:background="#0000FF"
/>
</FrameLayout>
代码示例
3.Relativelayout(相对布局)
android:layout_below //在某个组件的下面
android:layout_toLeftOf //在某个组件的左边
android:layout_toRinghtOf //在某个组件的右边
android:layout_alignTop //在某个组件上对齐
android:layout_alignBottom //在某个组件下对齐
android:layout_alignLeft //在某个组件左对齐
android:layout_alignRight //在某个组件右对齐
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tvr1"
android:layout_width="100px"
android:layout_height="100px"
android:background="#FF0000"
/>
<TextView
android:id="@+id/tvr2"
android:layout_width="80px"
android:layout_height="80px"
android:background="#00FF00"
android:layout_below="@+id/tvr1"
/>
<TextView
android:id="@+id/tvr3"
android:layout_width="60px"
android:layout_height="60px"
android:background="#0000FF"
android:layout_alignRight="@+id/tvr1"
/>
</RelativeLayout>
代码示例
4.TableLayout(表格布局)
注意:表格布局的组件要放在TableRow中
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <TableRow>
<TextView
android:layout_width="100px"
android:layout_height="100px"
android:background="#FF0000"
/>
</TableRow>
<TableRow>
<TextView
android:layout_width="80px"
android:layout_height="80px"
android:background="#00FF00"
/>
<TextView
android:layout_width="60px"
android:layout_height="60px"
android:background="#0000FF"
/>
</TableRow>
</TableLayout>
代码示例
5.AbsoluteLayout(绝对布局)
android:layout_x="80px" //x轴坐标值
android:layout_y="20px" //y轴坐标值
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tvr1"
android:layout_width="100px"
android:layout_height="100px"
android:background="#FF0000"
/>
<TextView
android:layout_x="60px"
android:layout_y="10px"
android:id="@+id/tvr2"
android:layout_width="80px"
android:layout_height="80px"
android:background="#00FF00"
android:layout_below="@+id/tvr1"
/>
<TextView
android:layout_x="80px"
android:layout_y="20px"
android:id="@+id/tvr3"
android:layout_width="60px"
android:layout_height="60px"
android:background="#0000FF"
android:layout_alignRight="@+id/tvr1"
/>
</AbsoluteLayout>
代码示例
Android的布局方式的更多相关文章
- 【深入篇】Android常用布局方式简介
LinearLayout 线性布局是程序中最常见的布局方式.一般分为水平线性布局和竖直线性布局,通过android.orientation属性可以设置线性布局的方向. 在布局中操作颜色时,要用的是十六 ...
- Android常规布局方式和方法
一.关于给控件添加ID属性 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xm ...
- android layout布局属性
参考:http://blog.csdn.net/msmile_my/article/details/9018775 第一类:属性值 true或者 false android:lay ...
- Android layout 布局 属性详解
第一类:属性值 true或者 false android:layout_centerHrizontal 水平居中 android:layout_centerVertical ...
- Android开发之基本控件和详解四种布局方式
Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...
- Android入门(十):界面的布局方式及其实际应用
关于Android界面布局,网上已经有了很多非常不错的学习资料,在这里我也不班门弄斧了,推荐两篇我认为写的不错的教程,然后再重点讲一下几种布局方式的实际应用. 教程链接:①http://www.cnb ...
- 【Android UI】Android开发之View的几种布局方式及实践
引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...
- Android 开发之旅:view的几种布局方式及实践
本文的主要内容就是分别介绍以上视图的七种布局显示方式效果及实现,大纲如下: 1.View布局概述 2.线性布局(Linear Layout) 2.1.Tips:android:layout_weigh ...
- Android 开发:view的几种布局方式及实践
View的几种布局显示方法,以后就不会在针对布局方面做过多的介绍.View的布局显示方式有下面几种:线性布局(Linear Layout).相对布局(Relative Layout).表格布局(Tab ...
随机推荐
- 创建pfx数字证书
相关参考: 安全工具: http://msdn.microsoft.com/zh-cn/library/dd233106(v=vs.110).aspx makecert: http://msdn.mi ...
- Python-装饰器、生成器
python中的for循环 for i in [1,2,3,4]: print(i) 正常可运行的,但是如下运行呢? for i in 1234 print(i) 结果: Traceback (mos ...
- redis的一些命令
字符串操作 EX在设置值的时候设置过期时间,ttl查看过期时间 expire能单独设置过期时间 查看所有的key key * 列表操作 lpush从列表左边添加值,rpush从列表右边添加值 lran ...
- Powerdesiger使用技巧
1.问题:使用CDM在生成LDM文件时,每次都生成Name(LDM)1,Name(LDM)2这样 , 同时遇到一个莫名其妙的问题,就是LDM或者PDM生成到了整个工程外的目录下 疑问回答:是因为原有的 ...
- 转:使用log4net完成程序异常日志记录(使用SQLite数据库记录和普通文本记录)
http://www.cnblogs.com/kyo-yo/archive/2010/06/11/use-log4net-to-log-exception.html 在前端时间开发的时候由于需要将异常 ...
- PolyBase--整合SQLServer和Hadoop
我们一直强调,大数据和传统的关系数据库并不对立,未来公司的的业务将会是大数据和关系型数据库的整合.微软的PolyBase打响了SQL Server和Hadoop整合的第一枪. 在2012年度的SQL ...
- oracle 任务使用
文章访问地址:http://www.cnblogs.com/hoojo/p/oracle_procedure_job_interval.html
- xx-net***简明使用教程
简介 继psiphon3.lantern.shadowsocks后,翻 土啬 界就来个新角色:xx-net 这张图是.2016.8.30日Google最新的搜索结果,还是可以看出这款工具的火爆程度的, ...
- Tomcat Connector 参数优化说明
默认参数 注: Connector 通常在%HOME_TOMCAT%/conf/servser.xml 文件内 # 正常参数 <Connector port=" protocol=&q ...
- SQL-ALTER-change和modify区别
ALTER 对于列的应用: 1.更改列名 格式:CHANGE old_col_name new_col_name column_definition 保留old和new列名 ...