需求
弹窗有收起状态,中间态,全部展开态。
方案
使用Google的BottomSheetBehavior。
具体使用可上官网了解:https://developer.android.google.cn/reference/com/google/android/material/bottomsheet/BottomSheetBehavior
实现
<!--父布局-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!--弹窗布局-->
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="200dp"
app:behavior_fitToContents="false"
app:behavior_halfExpandedRatio="0.55"
app:layout_behavior="@string/bottom_sheet_behavior">
...
</LinearLayout>
</androidx.constraintlayout.widget.