Android新手笔记—六大布局

一、LinearLayout—线性布局

首先是最基本的,所有布局都有的属性:
android:layout_width=“wrap_content” //wrap_content 包裹内容
android:layout_height=“match_parent” //match_parent 填充父容器

其次,进入线性布局:
android:orientation=“vertical”
//这是设置布局中控件排列方式的
//vertical 垂直摆放
//horizontal 水平摆放

还有gravity //内部控件的对齐方式

gravity中不常见的:
android:layout_gravity=“fill_horizontal” //必要时增加对象横向大小
android:layout_gravity=“fill_vertical” //必要时增加对象竖向大小

二、RelativeLayout—相对布局

android:layout_alignParentTop="true"  //指定是否与父布局顶部对齐,值为"true"或"false"。
android:layout_alignParentBottom="true"  //指定是否与父布局底部对齐,值为"true"或"false"。
android:layout_alignParentRight="true"  //指定是否与父布局右对齐,值为"true"或"false"。
android:layout_alignParentLeft="true"  //指定是否与父布局左对齐,值为"true"或"false"。

android:layout_above	  //属性值取为其他控件的id,指定控件的上方。
android:layout_below   //属性值取为其他控件的id,指定控件的下方。
android:layout_toLeftOf   //属性值取为其他控件的id,指定控件的左方。
android:layout_toRightOf   //属性值取为其他控件的id,指定控件的右方。

android:layout_alignTop   //属性值取为其他控件的id,指定控件的顶部对齐。
android:layout_alignBottom   //属性值取为其他控件的id,指定控件的底部对齐。
android:layout_alignLeft   //属性值取为其他控件的id,指定控件的左对齐。
android:layout_alignRight   //属性值取为其他控件的id,指定控件的右对齐。

android:layout_marginRight="20dp"  //与父布局右边相距
android:layout_marginLeft="20dp"  //与父布局左边相距
android:layout_marginTop="20dp"  //与父布局上边相距
android:layout_marginBottom="20dp"  //与父布局下边相距
android:layout_marginStart="20dp"  //与父布局下边相距,与Left的区别在于左边是否为开头
android:layout_marginBottom="20dp"  //与父布局下边相距,同Start

android:layout_centerInParent="true"  //与父布局水平垂直都居中
android:layout_centerHorizontal="true"  //与父布局水平居中
android:layout_centerVertical="true"  //与父布局垂直居中

在绝对布局中衍生出了一个增强的相对布局—ConstrainLayout,现如今有流行趋势。

三、FrameLayout—帧布局

后覆盖前

前三个为主要的三个布局

四、AbsoluteLayout—绝对布局

android:layout_x="60dp"
    android:layout_y="60dp"		//利用坐标定位

五、TableLayout—表格布局

android:stretchColumns="2"	//用来设置TableLayout的子标签TableRow的某列是否拉伸,相应的有shrinkColumns  设置收缩。
android:layout_column	//指定该单元格在第几列显示
android:layout_span	//指定该单元格占据的列数

六、GridLayout—网格布局

android:rowCount="6"	//设置行数
android:columnCount="4"	//设置列数
android:layout_columnSpan="2"	//设置占几列
android:layout_rowSpan="2"	//设置占几行
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值