2021-07-21 android常用基本布局

Android常用布局

LinearLayout 线性布局

	1)、线性布局:用来控制其子View(子视图)以水平或垂直方式展开显示
	2)、重要属性:
			1)、orientation(方向) : "vertical" 为垂直 "horizontal"为水平
			2)、layout_weight(权重)

在这里插入图片描述

LinearLayout 应用实例

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="To"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Subject"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="Message"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Reset"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Send"/>
    </LinearLayout>

</LinearLayout>

效果图·1
在这里插入图片描述

RelativeLayout 相对布局

	1)、相对布局:用来控制其子View(子视图)以相对定位的方法进行布局显示
	2)、相对布局时最灵活,最强大,也是学习难度最大的布局
	3)、相对布局相关属性比较多:
			1)、兄弟视图之间:同方向对齐,反方向对齐
					1)、同方向对齐属性:
							1)、android:layout_alignLeft   	 	 ---> 对齐左边界
							2)、android:layout_alignTop		 	 ---> 对齐上边界
							3)、android:layout_alignRight 		     ---> 对齐右边界
							4)、android:layout_alignBottom   	     ---> 对齐下边界
					2、反方向对齐属性:
							1)、android:layout_toLeftOf             ---> 当前视图在指定视图的左边
							2)、android:layout_toRightOf	         ---> 当前视图在指定视图的右边
							3)、android:layout_above			     --->当前视图在指定视图的上方
							4)、android:layout_below		   	  	---> 当前视图在指定视图的下方
			2)、与父视图之间:同方向对齐,居中
			左对齐:android:layout_alighParentLeft

							1)、右对齐:android:layout_alighParentRight

							2)、顶端对齐:android:layout_alighParentTop
							
							3)、底部对齐:android:layout_alighParentBottom
							
							4)、水平居中:android:layout_centerHorizontal
							
							5)、垂直居中:android:layout_centerVertical
							
							6)、中央位置:android:layout_centerInParent

在这里插入图片描述

RelativeLayout 应用实例

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- 编辑框 -->
    <EditText
        android:id="@+id/et_relative_msg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:hint="Message"/>

    <Button
        android:id="@+id/btn_relative_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OK"
        android:layout_below="@+id/et_relative_msg"
        android:layout_alignRight="@+id/et_relative_msg"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cancel"
        android:layout_alignTop="@+id/btn_relative_ok"
        android:layout_toLeftOf="@+id/btn_relative_ok"
        android:layout_marginRight="30dp"/>

</RelativeLayout>

效果图.1
在这里插入图片描述

FrameLayout 帧布局

	1)、帧布局中的每一个子VIew(子视图)都代表一个画面,默认以屏幕左上角作为(0,0)坐标,按定义的先后顺序逐次逐屏显示,
	后面出现的画面会覆盖前面的画面。
	
	2)、可以通过android:Layout——gravity等属性来指定子视图的位置
	3)、gravity : 控制的是当前视图的内容/子视图
	4)、layout_gravity :控制的是当前视图自己

FrameLayout 实例

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="280dp"
        android:layout_height="280dp"
        android:background="#33ffff"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="240dp"
        android:layout_height="240dp"
        android:background="#33ccff"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#3300ff"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="160dp"
        android:layout_height="160dp"
        android:background="#3333ff"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:background="#3366ff"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="#3399ff"
        android:layout_gravity="center"/>
</FrameLayout>

效果图.1
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值