android常用的布局

常用布局


共有属性

  • android:layout_width 宽度
  • android:layout_height 高度
  • android:layout_padding 内边距
  • android:layout_margin 外边距

1、LinearLayout线性布局

  • android:layout_orientation 方向
    • horizontal 水平(默认)
    • vertical 垂直
  • android:layout_weight 权重
    • 根据父类的屏幕尺寸划分
    • 如果指定该元素,一般要把android:layout_width=”0dp”,以免影响布局效果
  • android:layout_gravity 重力
    • right、left只对horizontal有效(因为水平,上下无空间,所以。。)
    • top、bottom只对vertical有效

2、Relativelayout相对布局

  • 相对于父容器(取值:true/false)

    • android:layout_centerInParent
    • android:layout_ alignParentLeft
    • android:layout_alignParentRight
    • android:layout_alignParentTop
    • android:layout_alignparentBottom
    • android:layout centerHorizontal
    • android:layout_centerVertical
  • 相对于其他控件(取值:其他控件id)

    1.在参照物的某边

    • android:layout_toLeftOf
    • android:layout_toRightOf
    • android:layout above
    • android:layout below

    2.和参照物的某达线对齐

    • android:layout_alignTop
    • android:layout_alignBottom
    • android:layout_alignLeft
    • android:layout_alignRight

3、FrameLayout帧布局

  • android:layout_gravity(控件重力)
  • android:gravity (相对于控件内容的位置布局)
  • android:foreground(前景图片)
  • android:foregroundGravity(前景重力)

4、 TableLayout表格布局

  • android:stretchColumns 设置可伸展的列(多列用,分割,所有用*)

  • android:shrinkColumns 设置可收缩的列

  • android:collapseColumns 设置可隐藏的列

      如果直接在TableLayout中添加控件,那么控件将和父容器等宽
      如果想让控件出现在同一行,那么这些控件的外层一定要加一对<TableRow>
      在TableRow中的控件,宽度都是默认wrap_content
    

5、GridLayout网格布局

  • android:rowCount(行数量)

  • android:columnCount(列数量)

  • android:layout_row(位于第几行)

     要使用下面的属性,必须搭配android:layout_gravity=fill,才有效果
    
  • android:layout_rowSpan(跨几行)

  • android:layout_columnSpan(跨几列)

6、ConstraintLayout约束布局

  • app:layout_constraintVertical_bias 水平偏移量,取值0~1 ,默认0.5
  • app:layout_constraintRight_toLeftOf=“id”
  •   app:layout_contraint本源_to目标="目标id"
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值