【问题标题】:Why GridLayoutManager is filling items from bottom to top and from right to left?为什么 GridLayoutManager 从下到上,从右到左填充项目?
【发布时间】:2018-12-15 12:10:58
【问题描述】:

我在 API 24、26、27 和 28 中测试了我的代码,它的工作原理非常棒(从上到下从左到右) 但是当我在 API 16 中对其进行测试时,我发现 GridLayoutManager 正在从 从下到上 和从 从右到左 填充项目.我猜这个问题发生在 API

这是我的代码:

RecyclerView recyclerView = v.findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
recyclerView.setAdapter(mAdapter);

如何在 API 16 中修复它?


编辑:

重要的是要知道 All Devices

【问题讨论】:

  • 测试用例试试这个GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 2,GridLayoutManager.VERTICAL,false);
  • 我在问问题之前对其进行了测试。它不起作用!
  • API 17 是第一个引入本机 RTL 支持的,因此问题可能来自于此。您的设备或活动是否配置为 RTL?
  • @Pawel 谢谢你的解释。它们都没有配置为 RTL。有什么解决办法吗?

标签: android android-layout android-recyclerview gridlayoutmanager


【解决方案1】:

当 Android 设备的 API 级别低于 17(4.2 或 JELLY_BEAN_MR1)时,我决定反转我的 ArrayList。

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
    Collections.reverse(mlist);
}

然后很明显我应该将mList设置为recyclerAdapter。

【讨论】:

    猜你喜欢
    • 2015-02-12
    • 2019-03-06
    • 2011-09-25
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    相关资源
    最近更新 更多