【发布时间】:2021-07-13 19:28:46
【问题描述】:
我的应用使用 BottomNavigationBar 在三个片段之间切换。其中一个片段在 ConstraintLayout 中包含一个 RecyclerView。 RecyclerView 将 BottomNavigationBar 向下推,使其不可见且无法使用。这是xml代码:
底部导航视图的主要活动
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_above="@id/bottom_navigation"
android:id="@+id/fragment_container"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:background="?android:attr/windowBackground"
android:theme="@style/BottomNavigationTheme"
app:labelVisibilityMode="unlabeled"
app:menu="@menu/nav_menu"
app:layout_scrollFlags="scroll|exitUntilCollapsed" />
</LinearLayout>
带有 RecyclerView 的片段
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</androidx.recyclerview.widget.RecyclerView>
</androidx.constraintlayout.widget.ConstraintLayout>
这就是我在片段容器中更改片段的方式
private fun setCurrentFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction().apply {
replace(R.id.fragment_container, fragment)
commit()
}
}
【问题讨论】:
标签: android kotlin android-fragments android-recyclerview