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

查看:7819
本文介绍了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.

推荐答案

从文档的<一个href="https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#setReverseLayout(boolean)">setReverseLayout

用于反向项遍历和布局顺序。这种行为类似于布局变化RTL意见。如果设置为true,第一个项目是奠定了在UI的结束,第二项是奠定了才等。对于水平布局,这取决于布局方向。如果设置为true,如果RecyclerView是LTR,比它会从RTL布局,如果RecyclerView}是RTL,它将从LTR布局。如果你正在寻找的完全相同的行为 setStackFromBottom(布尔),使用 setStackFromEnd(布尔)

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)

所以,尽量使用也<一href="https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#setStackFromEnd(boolean)">setStackFromEnd(boolean)您LinearLayoutManager例如,

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

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

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

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