Android基本布局|青训营笔记

101 阅读2分钟

这是我参与「第四届青训营 」笔记创作活动的第10天

本节课的主要内容: Android基本布局

1,linearlayout

linearlayout称为线性布局,该布局的功能主要为将其所包含的控件在线性方向上依次排列(如水平,垂直)
基本属性:
android:orientation 线性布局的方向(水平或者垂直)
android:background 线性布局的背景
android:width 线性布局的容器宽度
android:height 线性布局的容器高度
android:gravity 线性布局中,子容器相对于父容器所在的位置

2,Relativelayout

Relativelayout称为相对布局,该布局的主要功能为一个组件布局参照另一个组件布局而进行布局(如根据兄弟组件或者父容器)
根据兄弟组件来布局
左边 android:layout_toLeftOf
右边 android:layout_toRightOf
上方 android:layout_above
下方 android:layout_below
对齐上边界 android:layout_alignTop
对齐下边界 android:layout_alignBottom
对齐左边界 android:layout_alignLeft
对齐右边界 android:layout_alignRight
根据父容器来布局
左对齐 android:layout_alighParentLeft
右对齐 android:layout_alighParentRight
顶端对齐 android:layout_alighParentTop
底部对齐 android:layout_alighParentBottom
水平居中 android:layout_centerHorizontal
垂直居中 android:layout_centerVertical
中央位置 android:layout_centerInParent

3,Framelayout

Framelayout称为帧布局是最为简单的一种布局,该布局为每个加入其中的控件创建一个空白区域,称为一帧,每个控件占据一帧。采用帧布局时,所有控件都默认显示在屏幕左上角,并按照先后放入的顺序重叠摆放,先放入的将会在最底层,后放入的控件显示在最顶层。帧布局使用于图层设计。
基本属性:
foreground 属性设置帧布局容器的前景图像
foregroundGravity 属性设置图像的显示位置

4,ConstraintLayout

ConstraintLayout被称为约束布局,是一个使用“相对定位”灵活地确定微件的位置和大小的一个布局。
基本属性:
app:layout_constraintTop_toTopOf="" 我的顶部和谁的顶部对齐
app:layout_constraintBottom_toBottomOf="" 我的底部和谁的底部对齐
app:layout_constraintLeft_toLeftOf="" 我的左边和谁的左边对齐
app:layout_constraintRight_toRightOf="" 我的右边和谁的右边对齐
app:layout_constraintStart_toStartOf="" 我的开始位置和谁的开始位置对齐
app:layout_constraintEnd_toEndOf="" 我的结束位置和谁的结束位置对齐
app:layout_constraintTop_toBottomOf="" 我的顶部位置在谁的底部位置
app:layout_constraintStart_toEndOf="" 我的开始位置在谁的结束为止