BottomAppBar 上方的 ImageView
ImageView above BottomAppBar
我需要在父级的上边框和 BottomAppBar
的上边框之间放置一张图片,但是当我这样做时,我的 BottomAppBar
看起来不正确:
我的布局
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@color/colorGraySuper"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/containerBottomAppBar"
android:layout_width="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:layout_height="0dp">
</ImageView>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/containerBottomAppBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.fromsakuraso13.waifu.presentation.views.RoundedBottomAppBar
android:id="@+id/navigationBottom"
app:fabAlignmentMode="end"
app:leftTopCornerSize="10dp"
app:rightTopCornerSize="10dp"
android:backgroundTint="@android:color/white"
android:background="@drawable/bg_navigation_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
app:backgroundTint="@color/colorAccentLight"
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/navigationBottom" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
您应该始终使用 CoordinatorLayout
作为包含其他布局(如 ConstraintLayout
或 RelativeLayout
)的容器布局,它应该用作父布局来约束其他视图 here。但是,任何需要为 FAB
躲避 Snackbar
或使用 AppBarLayout
折叠工具栏等效果的视图都应作为 CoordinatorLayout
.
的直接子项放置
对于你的情况,我建议将视图放置如下:
<CoordinatorLayout>
<ConstraintLayout> //you can skip this if there are no other views except ImageView
<ImageView/>
</ConstraintLayout>
<RoundedBottomActionBar/>
<FloatingActionButton/>
</CoordinatorLayout/>
我需要在父级的上边框和 BottomAppBar
的上边框之间放置一张图片,但是当我这样做时,我的 BottomAppBar
看起来不正确:
我的布局
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@color/colorGraySuper"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@id/containerBottomAppBar"
android:layout_width="match_parent"
android:layout_marginBottom="40dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:layout_height="0dp">
</ImageView>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/containerBottomAppBar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.fromsakuraso13.waifu.presentation.views.RoundedBottomAppBar
android:id="@+id/navigationBottom"
app:fabAlignmentMode="end"
app:leftTopCornerSize="10dp"
app:rightTopCornerSize="10dp"
android:backgroundTint="@android:color/white"
android:background="@drawable/bg_navigation_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
app:backgroundTint="@color/colorAccentLight"
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/navigationBottom" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
您应该始终使用 CoordinatorLayout
作为包含其他布局(如 ConstraintLayout
或 RelativeLayout
)的容器布局,它应该用作父布局来约束其他视图 here。但是,任何需要为 FAB
躲避 Snackbar
或使用 AppBarLayout
折叠工具栏等效果的视图都应作为 CoordinatorLayout
.
对于你的情况,我建议将视图放置如下:
<CoordinatorLayout>
<ConstraintLayout> //you can skip this if there are no other views except ImageView
<ImageView/>
</ConstraintLayout>
<RoundedBottomActionBar/>
<FloatingActionButton/>
</CoordinatorLayout/>