RecyclerView无法应用于FlexboxLayoutManager

Cla*_*ous 1 android android-recyclerview

我正在尝试使用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);
Run Code Online (Sandbox Code Playgroud)

小智 5

如果您使用的是最新版本的Flexbox(1.1.0),它将使用AndroidX,因此FlexboxLayoutManager实际上会扩展androidx.recyclerview.widget.RecyclerView.LayoutManager,这可能导致此异常。尝试迁移到androidx; 使用androidx.recyclerview:RecyclerView:1.0.0作为recyclerview依赖应该解决您的问题。Android Studio在“重构”下具有“迁移到AndroidX”功能,您可以使用该功能进行迁移。