LinearLayoutManager setReverseLayout() == true 但项目从底部堆叠 [英] LinearLayoutManager setReverseLayout() == true but items stack from bottom

查看:19
本文介绍了LinearLayoutManager setReverseLayout() == true 但项目从底部堆叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个简单的解决方案,但似乎设置

This seems like it would be an easy solution, but it seems that setting

private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private LinearLayoutManager mLayoutManager;

.... // More code

    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);

    // Add item decoration
    mRecyclerView.addItemDecoration(new SpacesItemDecoration(DIVIDER_SPACE));

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setReverseLayout(true); // THIS ALSO SETS setStackFromBottom to true
    mRecyclerView.setLayoutManager(mLayoutManager);

似乎还设置了从底部堆叠的项目

Seems to also set the items to stack from the bottom

我尝试将 setStackFromBottom 设置为 false 但这没有任何作用,什么是颠倒项目顺序但仍从顶部填充的最佳方法?我应该改用自定义比较器类吗?我希望这比创建另一个类更容易.

I tried to set setStackFromBottom to false but that didn't do anything, what would be the best way to reverse the items order but still populate from the top? Should I use a Custom Comparator class instead? I was hoping this would be an easier process than creating another class.

推荐答案

来自 setReverseLayout

用于反转项目遍历和布局顺序.这与 RTL 视图的布局更改类似.当设置为 true 时,第一项布置在 UI 的末尾,第二项布置在它之前等等.对于水平布局,这取决于布局方向.设置为true时,如果RecyclerView为LTR,则从RTL布局,如果RecyclerView}为RTL,则从LTR布局.如果您正在寻找与 setStackFromBottom(boolean) 完全相同的行为,请使用 setStackFromEnd(boolean)

Used to reverse item traversal and layout order. This behaves similar to the layout change for RTL views. When set to true, first item is laid out at the end of the UI, second item is laid out before it etc. For horizontal layouts, it depends on the layout direction. When set to true, If RecyclerView is LTR, than it will layout from RTL, if RecyclerView} is RTL, it will layout from LTR. If you are looking for the exact same behavior of setStackFromBottom(boolean), use setStackFromEnd(boolean)

所以,也尝试使用 setStackFromEnd(boolean) 在你的 LinearLayoutManager 实例上,

So, try also using setStackFromEnd(boolean) on your LinearLayoutManager instance,

LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);

这篇关于LinearLayoutManager setReverseLayout() == true 但项目从底部堆叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆