我正在尝试创建一个使用RecyclerView
在列表中显示数据的应用程序,在LinearLayoutManager
中有一个选项可以设置堆栈的结束和反向布局,以便我显示最新的数据列表的顶部。无论如何,我可以在交错的网格布局中显示位置0(顶部)的最新数据吗?
答案 0 :(得分:3)
StaggeredGridLayoutManager
的方法为setReverseLayout。
像这样使用:
mLayoutManager = new StaggeredGridLayoutManager(getActivity());
mLayoutManager.setReverseLayout(true);
答案 1 :(得分:1)
您可以使用GridLayoutManagaer
。在构造函数中,您可以将true/false
传递给反向布局,也可以使用setReverseLayout(boolean)
方法。检查this
答案 2 :(得分:0)
您可以在更新(插入)数据后(需要时)滚动到末尾
private void updateData(@NonNull List<Item> items, boolean moveToTheEnd) {
adapter.updateItems(items);
if(moveToTheEnd) {
recyclerView.scrollToPosition(adapter.getItemCount() - 1);
}
}