【发布时间】:2019-09-23 17:40:04
【问题描述】:
我已经实现了单活动多片段应用程序设计。我将约束布局作为活动的根,并且框架布局在我的应用程序中托管所有片段。我还有一个底部导航视图(来自 com.google.android .material.bottomnavigation.BottomNavigationView)。 我想拥有一个包含所有片段用户界面的底部导航视图。
问题:我在渲染底部导航视图时遇到问题。它不会粘在父级的底部,它只是浮动在布局中。 我在底部导航视图上应用的约束似乎无法正常工作,或者可能是我没有正确使用它们。
观察:我尝试了一些配置来理解问题。我将背景颜色应用于约束布局(黑色),将应用程序的强调色应用于框架布局,并观察到约束用于底部导航视图未正确应用。 当我启动应用程序时,底部导航视图浮动,然后遵循约束并正常工作,但是当我暂停活动然后恢复活动后,底部导航视图无法遵循约束。
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".module.MainView">
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="@dimen/_0dp"
android:layout_above="@id/bottom_navigation"
android:background="@color/colorAccent"
android:padding="@dimen/_1dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="@dimen/_0dp"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:itemIconTint="@color/colorNavIcon"
app:itemTextColor="@color/colorNavText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/wkd_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
活动开始时的布局:
活动简历布局:
底部导航视图下方的黑色区域是约束布局。 每次打开特定片段时,我都希望底部导航视图遵循约束。
【问题讨论】:
标签: android android-fragments android-constraintlayout android-framelayout bottomnavigationview