android 布局总结

1,线性布局
LinearLayout是线性布局,包含的子控件是以横向或竖向排列
android:orientation="vertical","horizontal"
android:gravity="bottom|center_horizontal"决定xy的位置
center_vertical:垂直(Y轴)居中
center_horizontal:水平(x轴)居中
center:水平垂直都居中
right:子类控件位于布局的右边
left:子类控件位于布局的左边
bottom:子类控件位于布局的底面
android:layout_gravity="bottom"---控件本身在父容器的xy位置
android:layout_wdight="1"---控件本身占父容器的比例
===>注意区分layout_height,为wrap_content时按比例走,为match_parent时按反比例走
布局之间可以套用,在垂直排布的线性布局中套入一个水平排布的线性布局
2,相对布局
RelativeLayout:包含的子控件以控件之间的位置或子类控件相对父类容器的位置的方式排列
android:layout_alignParentBottom="true",子类控件相对父类容器靠底部,会与相对布局的wrap_content冲突
android:layout_alignLeft="+id/...",子类控件相对控件...左对齐
android:layout_toLeftof="+id/..."控件唯一控件...左边
android:layout_centerInParent="true",子类控件相对父类容器水平垂直居中
android:layout_centerHorizontal="true",子类控件相对父类容器水平居中
android:layout_centerVertical="true",子类控件相对父类容器垂直居中
android:layout_marginBottom="10dp",当底部无其他控件时,此属性不起作用
3,网格布局
android:orientation="vertical","horizontal"
android:gravity="bottom"决定xy的位置
android:rowCount="4"设置网格布局的行数
android:columnCount="4"设置网格布局列数
android:layout_row="2"设置控件唯一第几行
android:layout_column="2"设置控件唯一第几列
android:layout_rowSpan="2"设置控件占几行
android:layout_column="2"设置控件占几列
4,百分比布局
包括PercentRelativeLayout和PercentFrameLayout
app:layout_widthPercent="20%"控件宽度布局的20%
app:layout_heightPercent="20%"控件高度布局的20%
app:layout_marginPercent="10%"控件的margin为20%(left,right,top,bottom)
5,帧布局
所有子控件都不能指定位置,都放于左上角,后一个元素覆盖前一个元素
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值