介绍:
CoordinatorLayout 是一个加强版的FrameLayout,可以监听它里面的所有子控件,然后自动做出合理的响应,用法和FrameLayout一样。
用法
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btn_float_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="20dp"
android:elevation="8dp"
android:src="@drawable/add"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
在用FrameLayout的时候,悬浮按钮底部出现的SnackBar会遮住悬浮按钮,如果用CoordinatorLayout,出现SnackBar的时候,会自动把悬浮按钮向上移动。