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>
代码示例
最新文章
- 怎么找到苹果App Store的应用程序下载链接地址
- copy-paste component
- 学习WebSocket(二):使用Spring WebSocket做一个简单聊天室
- 【131202】SQL
- java如何得到GET和POST请求URL和参数列表(转)
- C++ 多态的实现原理与内存模型
- appium跑demo简单实例讲解
- python中的类,对象,方法,属性等介绍
- ANT编译build.xml
- Unity3d:Unknown type &#39;System.Collections.Generic.CollectionDebuggerView&#39;1
- MySQL5.7.12新密码登录方式及密码策略
- Java中final、finally和finalize的区别(转)
- LINUX怎么修改IP地址
- 使用cl编译C/C++
- SparkSQL
- Python多版本共存(生产环境)
- 基于UML的高校教务管理系统的设计与实现
- java发送邮件高级篇
- 创建servlet程序知识点详解---servlet-day12
- CSDN 个性 博客 栏目 自定义 栏目 酷炫 音乐 视频