安卓java帧布局_Android开发之六大常用布局,你知道了吗?

网上有人比喻的很好:布局好比是建筑里的框架,组件按照布局的要求依次排列,就组成了用于看见的漂亮界面了。

布局类型

b1b66d52cc575d24d3b6b949b91c640f.png

1. LinearLayout (线性布局)

线性布局是按照水平或垂直的顺序将子元素(可以是控件或布局)依次按照顺序排列,每一个元素都位于前面一个元素之后。线性布局分为两种:水平方向和垂直方向的布局。分别通过属性 android:orientation="vertical" 和 android:orientation="horizontal" 来设置。

示例代码:

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="4" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="5" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="6" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="+" >

2. RelativeLayout (相对布局)

RelativeLayout 继承于 android.widget.ViewGroup,其按照子元素之间的位置关系完成布局的,作为Android系统五大布局中最灵活也是最常用的一种布局方式,非常适合于一些比较复杂的界面设计。

示例代码:

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:layout_centerHorizontal="true"

android:text="Button1"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toLeftOf="@id/btn1"

android:layout_above="@id/btn1"

android:text="Button2"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/btn1"

android:layout_above="@id/btn1"

android:text="Button3"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/btn2"

android:layout_toLeftOf="@id/btn3"

android:layout_above="@id/btn2"

android:text="Button4"

>

3. TableLayout (表格布局)

表格布局,适用于多行多列的布局格式,每个TableLayout是由多个TableRow组成,一个TableRow就表示TableLayout中的每一行,这一行可以由多个子元素组成。实际上TableLayout和TableRow都是LineLayout线性布局的子类。但是TableRow的参数android:orientation属性值固定为horizontal,且android:layout_width=MATCH_PARENT,android:layout_height=WRAP_CONTENT。所以TableRow实际是一个横向的线性布局,且所以子元素宽度和高度一致。

4. FrameLayout (帧布局)

放入的所有控件都被放置在最左上的区域;

无法为控件指定一个确切的位置;

下一个子控件会重叠覆盖上一个子控件。

5. AbsoluteLayout (绝对布局)

采用坐标轴的方式定位控件;

左上角是(0,0)点,往右X轴递增,往下Y轴递增;

定位属性: android:layout_x、android:layout_y

6. ConstraintLayout (约束布局)

ConstraintLayout是Android Studio 2.2中主要的新增功能之一;

ConstraintLayout非常适合使用可视化的方式来编写界面;

ConstraintLayout 可以有效地解决布局嵌套过多的问题。 目前,Android Studio 是 2.2或以上版本默认布局文件首选就是 ConstraintLayout。 ###最后 今年金九银十我花一个月的时间收录整理了一套知识体系,如果有想法深入的系统化的去学习的,可以点击传送门,我会把我收录整理的资料都送给大家,帮助大家更快的进阶。

format,png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值