gpt4 book ai didi

java - LinearLayoutManager setReverseLayout() == true 但项目从底部堆叠

转载 作者:IT王子 更新时间:2023-10-29 00:04:39 28 4
gpt4 key购买 nike

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

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);

似乎也将元素设置为从底部堆叠

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

最佳答案

来自 setReverseLayout 的文档

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 实例上,

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

关于java - LinearLayoutManager setReverseLayout() == true 但项目从底部堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27727354/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com