【发布时间】:2015-10-18 11:22:13
【问题描述】:
我正在使用RecyclerView 和GridLayoutManager。在那个布局管理器上,我调用setReverseLayout(true),所以元素以相反的顺序显示。
但是现在,RecyclerView 最初是从列表末尾显示的。我知道有一个setStackFromEnd(boolean) 方法,但是它与GridLayoutManager 不兼容。
以相反的顺序显示元素并且仍然从顶部显示RecyclerView 的最佳方式是什么?
这是我使用RecyclerView的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mgaetan89.showsrage.fragment.ShowsSectionFragment">
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/grid_margin"
android:clipToPadding="false"
android:paddingBottom="@dimen/fab_spacing"/>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/no_shows"
android:visibility="gone"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end|right"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_black_24dp"/>
</FrameLayout>
【问题讨论】:
-
在
getCount() - position - 1检索项目? -
@MrsEd 我将我的布局添加到我的原始帖子中。 @Blackbelt 那可以工作。但这不是在
Adapter中加入一些LayoutManager逻辑吗? -
我最终使用@Blackbelt 解决方案,即使我认为有更好的方法。
-
如果你找到了,别忘了分享一下
-
如果您从 ArrayList 填充网格,您可以使用 Collections.reverse(array); 反转它
标签: android android-recyclerview gridlayoutmanager