我的应用程序使用BottomNavigationBar在三个片段之间切换。其中一个片段在ConstraintLayout中包含一个RecyclerView。RecyclerView将BottomNavigationBar向下推,使其不可见且不可用。下面是xml代码:
BottomNavigationView的主要活动
<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()
}
}发布于 2021-07-14 05:13:55
我是android新手,所以我的答案可能是错的。
将片段中的layout_height = "match_parent“替换为layout_height = "wrap_content”(首先尝试循环视图,然后尝试约束布局,如果没有,请尝试同时更改循环视图和约束布局)
https://stackoverflow.com/questions/68368349
复制相似问题