Android 布局管理器之LinearLayout

线性布局(LinearLayout)

常用属性:

  1. id属性
    唯一标识
#设置id
android:id="@+id/ll1"
  1. layout_width,layout_height
    设置宽度、高度,有三种形式:
    1、match_parent 和父容器匹配
    2、wrap_content 包含内容
    3、xxdp 自定义大小,单位一般使用pd,字体大小一般使用sp
#设置宽度为匹配父容器
#设置高度为200dp
android:layout_width="match_parent"
android:layout_height="200dp"
  1. background
    设置背景
#设置背景为红色
android:background="#ff0000"
  1. orientation
    设置排列方式,有两种排列方式:
    1、vertical 垂直排列
    2、horizontal 水平排列
#设置为垂直排列
android:orientation="vertical"

vertical

  1. layout_margin
    外边距,设置蓝色块的外边距为60dp,效果如图
    layout_margin
  2. padding
    内边距,设置最外层容器内边距为50dp,效果如图
    padding
  3. gravity
    内部元素对其方式
    center 居中
    center_vertical 垂直居中
    center_horizontal 水平居中
    top 靠上
    bottom 靠下
    等等
    设置蓝色块中的元素居中,如图center
  4. layout_weight
    权重,两个view的weight都设置为1,那么这两个view会平分剩下的部分,即减去50dp后剩下的部分平分,所以view1比view2多50dp,如果第一个view的width也为0dp,那么这两个view等分。weight值越大,分到的越多。
    weight
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值