Android 布局

线性布局LinearLayout

属性

  • android:orientation:设置布局方向
    • vertical:垂直方向
      在这里插入图片描述

      • horizontal:水平方向
        在这里插入图片描述
  • android:gravity:设置子元素对齐方式
    • top、bottom、start、end、left、right 支持以|分隔的多个组合
    • android:layout_gravity:在子控件使用,设置子控件在父控件的位置
      在这里插入图片描述
  • android:weightSum: 在布局方向上将剩余空间分成几份(单独配置无效)
    • android:layout_weight: 设置子空间占用几份
      在这里插入图片描述
      可以看到父控件将剩余空间分成3份,textView占用空间是button的2倍
      注意:weightSum是可以不设置的。如果weightSum没有设置,Android会根据子组件所设置的layout_weight计算出weightSum的值。
  • android:divider:为LinearLayout设置分割线所使用的的图片 需要配置android:showDividers使用
  • android:showDividers:设置分割线所在位置,值为:none, middle, begining, end
  • android:dividerPadding:设置分割线的Padding。

相对布局RelativeLayout

属性

  1. android:gravity: 控制该组件所包含的子元素的对齐方式,可以以|分隔组合使用
  2. android:ignoreGravity:设置该组件是否受gravity影响,ture不受影响,反之受影响
  3. 根据父组件定位
    • android:layout_alignParentLeft:左对齐
    • android:layout_alignParentRight:右对齐
    • android:layout_alignParentTop:顶部对齐
    • android:layout_alignParentBottom:底对齐
    • android:layout_centerHorizontal:水平居中
    • android:layout_centerVertical:垂直居中
    • android:layout_centerInParent:根据父容器位置居中
  4. 根据同级组件对齐 (值是同级组件id)
    • android:layout_toLeftOf:在同级组件左侧
    • android:layout_toRightOf:在同级组件右侧
    • android:layout_above:在同级组件上面
    • android:layout_below:在同级组件下面
    • android:layout_alignTop:在同级组件的上边界
    • android:layout_alignBottom:在同级组件的下边界
    • android:layout_alignLeft:在同级组件的左边界
    • android:layout_alignRight:在同级组件的右边界

表格布局TableLayout

属性

  1. android:collapseColumns:需要被隐藏的列序号,从0开始
  2. android:shrinkColumns:允许收缩的列序号,从0开始
  3. android:layout_column:跳过几个,从0开始
  4. android:layout_span:合并几个单元格

帧布局FrameLayout

属性

  1. android:foreground:设置改帧布局容器的前景图像
  2. android:foregroundGravity:设置前景图像显示的位置

在这里插入图片描述

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    xmlns:tools="http://schemas.android.com/tools"    
    android:id="@+id/FrameLayout1"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"    
    tools:context=".MainActivity"     
    android:foreground="@drawable/logo"    
    android:foregroundGravity="right|bottom">    
    
    <TextView    
        android:layout_width="200dp"    
        android:layout_height="200dp"    
        android:background="#FF6143" />    
    <TextView    
        android:layout_width="150dp"    
        android:layout_height="150dp"    
        android:background="#7BFE00" />    
     <TextView    
        android:layout_width="100dp"    
        android:layout_height="100dp"    
        android:background="#FFFF00" />    
        
</FrameLayout> 

网格布局GridLayout

属性

  1. android:orientation: 设置布局方向
    • horizontal:水平方向
    • vertical:竖直方向
  2. android:layout_gravity: 设置子控件在父控件的位置
  3. android:rowCount:网格布局行数
  4. android:columnCount:网格布局列数
  5. android:layout_row:设置组件在哪一行
  6. android:layout_column:设置组件在哪一列
  7. android:rowSpan:设置组件合并哪几行
  8. android:columnSpan:设置组件合并那几列

约束布局ConstraintLayout

属性

  1. 方向约束
    1. app:layout_constraintTop_toTopOf=“” 我的顶部和谁的顶部对齐
    2. app:layout_constraintBottom_toBottomOf=“” 我的底部和谁的底部对齐
    3. app:layout_constraintLeft_toLeftOf=“” 我的左边和谁的左边对齐
    4. app:layout_constraintRight_toRightOf=“” 我的右边和谁的右边对齐
    5. app:layout_constraintStart_toStartOf=“” 我的开始位置和谁的开始位置对齐
    6. app:layout_constraintEnd_toEndOf=“” 我的结束位置和谁的结束位置对齐
    7. app:layout_constraintTop_toBottomOf=“” 我的顶部位置在谁的底部位置
    8. app:layout_constraintStart_toEndOf=“” 我的开始位置在谁的结束为止
    9. …以此类推
  2. 基线对齐
    app:layout_constraintBaseline_toBaselineOf=“”
  3. 角度约束
    • app:layout_constraintCircle=“” 目标控件id
    • app:layout_constraintCircleAngle=“” 对于目标的角度(0-360)
    • app:layout_constraintCircleRadius=“” 到目标中心的距离
  4. 百分比偏移
    • app:layout_constraintHorizontal_bias=“” 水平偏移 取值范围是0-1的小数
    • app:layout_constraintVertical_bias=“” 垂直偏移 取值范围是0-1的小数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值