按比例布局
宽度满屏,高度9:16
<androidx.constraintlayout.widget.ConstraintLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="0dp"app:layout_constraintTop_toTopOf="parent"app:layout_constraintDimensionRatio="w,9:16"></RelativeLayout></androidx.constraintlayout.widget.ConstraintLayout>
一分为二
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/mainLayout"android:layout_width="match_parent"android:layout_height="match_parent"><Viewandroid:id="@+id/view_top"android:layout_width="match_parent"android:layout_height="0dp"app:layout_constraintRight_toRightOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBottom_toTopOf="@+id/ll_headView"/><LinearLayoutandroid:id="@+id/ll_headView"android:layout_width="match_parent"android:layout_height="0dp"app:layout_constraintHeight_percent="0.58"app:layout_constraintRight_toRightOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintBottom_toBottomOf="parent"android:background="@drawable/corners_white_top_bg"android:orientation="vertical">
使用RelativeLayout即可实现重叠布局——RelativeLayout标签内容里面的下层布局会浮现在上层布局之上;上层布局会被下层布局覆盖
实现layout:
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="200dp"android:background="#FFE4C4"><LinearLayoutandroid:layout_width="300dp"android:layout_height="100dp"android:background="#303F9F"></LinearLayout><LinearLayoutandroid:layout_width="200dp"android:layout_height="100dp"android:background="#FF4081"android:layout_marginLeft="50dp"android:layout_marginTop="50dp"></LinearLayout> </RelativeLayout>