CoordinatorLayout
常见的应用场景:
示例代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- AppBarLayout 用于控制顶部的 Toolbar 和其他控件 -->
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/sample_image" />
<!-- NestedScrollView 里面可以嵌套其他内容,支持滚动 -->
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 你的其他内容 -->
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<!-- FloatingActionButton,配合 CoordinatorLayout 使用时支持动态交互 -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_fab"
app:layout_anchorGravity="bottom|end"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>Last updated