LinearLayout(线性布局)
就是水平布局和垂直布局
控件会一个挨着一个
android:orientation就控制是水平布局或者是垂直布局
vertical表示垂直布局
horizontal表示水平方向
android:gravity表示内部控件的对齐方式
有center,center_vertical,center_horizontal,top、bottom,left,right
RelativeLayout(相对布局)
相对布局可以让子控件相对于兄弟控件或父控件进行布局
相对于父控件
android:layout_alignParentTop 控件的顶部与父控件的顶部对齐
android:layout_alignParentBottom 控件的底部与父控件的底部对齐
android:layout_alignParentLeft 控件的左部与父控件的左部对齐
android:layout_alignParentRight 控件的右部与父控件的右部对齐
比如
1 | android:layout_alignParentTop=“true” |
相对于给定Id控件
android:layout_above 控件的底部置于给定ID的控件之上
android:layout_below 控件的底部置于给定ID的控件之下
android:layout_toLeftOf 控件的右边缘与给定ID的控件左边缘对齐
android:layout_toRightOf 控件的左边缘与给定ID的控件右边缘对齐
android:layout_alignBaseline 控件的baseline与给定ID的baseline对齐
android:layout_alignTop 控件的顶部边缘与给定ID的顶部边缘对齐
android:layout_alignBottom 控件的底部边缘与给定ID的底部边缘对齐
android:layout_alignLeft 控件的左边缘与给定ID的左边缘对齐
android:layout_alignRight 控件的右边缘与给定ID的右边缘对齐
比如
1 | android:layout_above=“@id/**” |
居中
android:layout_centerHorizontal 水平居中
android:layout_centerVertical 垂直居中
android:layout_centerInParent 父控件的中央
比如
1 | android:layout_centerInParent=“true” |
ConstraintLayout(约束布局)
layout_constraintTop_toTopOf 将所需视图的顶部与另一个视图的顶部对齐
layout_constraintTop_toBottomOf 将所需视图的顶部与另一个视图的底部对齐
layout_constraintBottom_toTopOf 将所需视图的底部与另一个视图的顶部对齐
layout_constraintBottom_toBottomOf 将所需视图的底部与另一个视图的底部对齐
layout_constraintLeft_toLeftOf 将所需视图的左边与另一个视图的左边对齐
layout_constraintLeft_toRightOf 将所需视图的左边与另一个视图的右边对齐
layout_constraintRight_toLeftOf 将所需视图的右边与另一个视图的左边对齐
layout_constraintRight_toRightOf 将所需视图的右边与另一个视图的右边对齐
比如
1 | app:layout_constraintTop_toBottomOf="@+id/***" |