必须为以下之一:RecyclerView.HORIZONTAL,RecyclerView.VERTICAL

时间:2019-07-11 13:15:29

标签: android android-recyclerview androidx

升级到AndroidX后,我在设置LayoutManager时收到此错误“ 必须是以下之一:RecyclerView.HORIZONTAL,RecyclerView.VERTICAL ”。

tournamentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));

问题ID:WrongConstant。

检查信息:确保方法中的参数仅允许一组特定的常量时,调用遵循这些规则

2 个答案:

答案 0 :(得分:1)

似乎您正在尝试将项目垂直放置在RecyclerView中,这是LinearLayout的默认行为

更改此

tournamentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));

对此

tournamentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

答案 1 :(得分:0)

如警告所示,将LinearLayoutManager.VERTICAL更改为RecyclerView.VERTICAL即可正常运行

示例:

tournamentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));

相关问题