java - 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 不会绘制任何内容(屏幕截图)。
请帮我解决问题!谢谢。
解决方案
推荐阅读
- java - java中的ProcessBuilder不执行'java -jar'命令
- ocaml - 执行微分的 OCaml 函数
- sql - 在 SQL Server 中创建数据文件 - 数据/表将如何分布?
- ubuntu - ttf-mscorefonts-installer 无法安装,下载错误
- django - Django:将变量添加到模板标签
- java - 用于在 ElasticSearch 中索引文档的 Java ThreadPoolExecutor
- python - Numpy直方图参数
- ios - 具有多个范围选择的 UISearchBar
- c# - UWP C#动态添加按钮并在StackPanel上组织
- java - 为什么在 AbstractQueuedSynchronize enq(final Node node) 方法中有一个 for(;;)