问题描述
我想在Android导航栏顶部为FrameLayout设置一个约束。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
app:labelVisibilityMode="labeled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_navigation"
app:itemIconTint="@color/colorPrimaryDark"
app:itemTextColor="@color/colorAccent"
/>
<FrameLayout
android:id="@+id/container_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
我用以下方法尝试过:
但是它所导致的布局看起来并不严格。在这里您可以看到屏幕截图: 你有什么想法我该怎么办?感谢您的每条评论,并感谢您的帮助。
解决方法
使用
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintTop_toTopOf="parent"
在您的FrameLayout中