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 ...
随机推荐
- java反射基础知识(五)反射应用实践
详解Java反射各种应用 Java除了给我们提供在编译期得到类的各种信息之外,还通过反射让我们可以在运行期间得到类的各种信息.通过反射获取类的信息,得到类的信息之后,就可以获取以下相关内容: Cl ...
- ES6的十个新特性
这里只讲 ES6比较突出的特性,因为只能挑出十个,所以其他特性请参考官方文档: /** * Created by zhangsong on 16/5/20. */// ***********Nu ...
- SQL联接 外联接 内联接 完全联接 交叉联接
联接分为: 内联接 [inner join] 外联接 (左外联接,右外联接) [left join/left outer jo ...
- web.xml配置之<context-param>详解
读完本文,你将了解(1)<context-param>的作用和用法,(2)<context-param>配置和<init-param>的区别 <context ...
- c#的yield return
4.1 迭代器块 一个迭代器块(iterator block)是一个能够产生有序的值序列的块.迭代器块和普通语句块的区别就是其中出现的一个或多个yield语句. yield return语句产生迭代的 ...
- asp.net MVC 强类型视图表单Ajax提交的注意事项
xmfdsh这几天遇到这么一个问题,在MVC中通过model模型生成的强类型视图的表单,在提交后的回调函数并没有发挥作用.如下图: 如上图,无论是通过Ajax.BeginForm或者Html.Begi ...
- ubuntu中在Launcher上添加Android Studio的运行图标
运行命令创建desktop文件: sudo gedit /usr/share/applications/android_studio.desktop 打开窗口后输入以下内容,注意Exec和Icon要修 ...
- Linux 进程管理 kill、killall、pkill命令
Linux常用信号(进程间通信) 系统中可以识别的信号较多,我们可以使用命令"kill -l"或"man 7 signal"来查询.命令如下: [root@lo ...
- cmd命令 启动 和关闭sql服务
(1)在操作系统的任务栏中单击“开始”菜单,选择“运行”命令,在下拉列表框中输入“cmd”命令,单击“确定”按钮. (2)输入如下命令,即可通过SQL Server命令行启动.停止或暂停的服务. SQ ...
- ICMP与PING解析
1.ICMP格式 ICMP是(Internet Control Message Protocol)Internet控制报文协议.它是TCP/IP协议族的一个子协议,用于在IP主机.路由器之间传递控制消 ...