首页 > 解决方案 > BottomSheetBehaviour 中的 RecyclerView 问题(未绘制内容。)

问题描述

伙计们。无法处理问题。我正在寻求一些建议。

我有一个带有 RecyclerView 的 BottomSheetBehaviour(和其他界面元素)。RecyclerView 可以包含很多内容,即当所有内容都没有进入屏幕时它必须滚动。

当很少的内容被加载到 RecyclerView(很少的元素)中时,它会正确地绘制所有内容。BottomSheetBehaviour 正常工作(链接到屏幕截图)。

但是,如果我下载了很多内容,RecyclerView 不再绘制它(链接到屏幕截图)。

我附上下面的标记代码。

<?xml version="1.0" encoding="utf-8"?>
<layout
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">
<data>
    <variable name="data" type=".controls.ControlSelectCategoriesFragment"/>
</data>
<FrameLayout
    style="?AppTheme.BottomSheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:elevation="4dp"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    tools:context=".controls.ControlSelectDateFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:background="?attr/AppTheme.ColorBottomSheetBackground"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintTop_toTopOf="parent">

           <CODE HEADER id/header>

            <RelativeLayout
                android:id="@+id/recycler_view1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/header"
                app:layout_constraintBottom_toTopOf="@+id/accept_button">
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:adjustViewBounds="true"
                    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" />
            </RelativeLayout>


             <CODE BUTTON id/accept_button>

        </androidx.constraintlayout.widget.ConstraintLayout>
    </LinearLayout>
</FrameLayout>
</layout>

下面我附上将适配器添加到 RecyclerView 的代码

private void prepareData(){
    listCategoriesAdapter = new ListCategoriesAdapterV2(parentContext, SessionManager.getInstance().getDataManager().findCategoriesByType(type), R.layout.view_category_hexagonal_item);
    listCategoriesAdapter.setModeSelecting(TypeSelectingModeAdapter.Single);
    listCategoriesAdapter.setVisibilityDetails(true);

    updateRecyclerView();
}
private void updateRecyclerView() {
    if (binder != null) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) binder.recyclerView.getLayoutManager();
        gridLayoutManager.setSpanCount(Math.min(4, listCategoriesAdapter.getElementsSize()));
        binder.recyclerView.setAdapter(listCategoriesAdapter);
    }
}

结果,如果 BottomSheetDialog 没有全屏打开(没有足够的内容),我的 RecyclerView 工作正常(截图)。如果内容很多且 BottomSheetDialog 全屏打开,则 RecyclerView 不会绘制任何内容(屏幕截图)

请帮我解决问题!谢谢。

标签: javaandroidandroid-fragmentsandroid-recyclerviewbottom-sheet

解决方案


推荐阅读