android - RecyclerView 无法应用于 FlexboxLayoutManager
问题描述
我正在尝试使用FlexboxLayoutManager
,我按照教程进行操作,但遇到了这个问题:
RecyclerView中的setLayoutManager(android.support.v7.widget.RecyclerView.LayoutManager)不能应用到(com.google.android.flexbox.FlexboxLayoutManager)
这是我的代码:
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(FreightResultActivity.this);
layoutManager.setFlexDirection(FlexDirection.COLUMN);
layoutManager.setJustifyContent(JustifyContent.FLEX_END);
recyclerView.setLayoutManager(layoutManager);
解决方案
如果您使用的是最新版本的 Flexbox (1.1.0),它会使用 AndroidX,因此FlexboxLayoutManager
实际 extendsandroidx.recyclerview.widget.RecyclerView.LayoutManager
可能会导致此异常。尝试迁移到androidx;androidx.recyclerview:RecyclerView:1.0.0
用作 recyclerview 依赖项应该可以解决您的问题。Android Studio 在“重构”下具有“迁移到 AndroidX”功能,您可以使用它来进行迁移。
推荐阅读
- scala - Spark:java.lang.NullPointerException 仅在集群模式下(在本地模式下运行良好!)
- java - 在一定数量的迭代后停止循环,而不是在达到最大值时停止
- php - Elementor 扩展:如何将转发器项目标题设置为选择的当前值
- mongodb - MongoDB Group BY 中缺少标题
- javascript - Highcharts:使用数组作为数据系列 - 排序
- scala - Databricks - 无法从 DataFrame 写入 Delta 位置
- c# - 如何覆盖委托参数?
- javascript - 如何使用 php 和 symfony 4 获取两个日期之间的差异?
- windows - ffmpeg - 报告文件级别无效(Windows)
- google-cloud-platform - 在 Cloud Endpoints 后面隐藏 Cloud Functions 执行