【问题标题】:RecyclerView with GridLayoutManager and reverse layout stack to bottomRecyclerView 与 GridLayoutManager 和反向布局堆栈到底部
【发布时间】:2015-10-18 11:22:13
【问题描述】:

我正在使用RecyclerViewGridLayoutManager。在那个布局管理器上,我调用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


【解决方案1】:

我厌倦了找到回收站视图的解决方案,所以最后我使用了 GridView

<GridView
    android:id="@+id/lv_explore"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:dividerHeight="0dip"
    android:horizontalSpacing="5dp"
    android:numColumns="3"
    android:scrollbars="none"
    android:verticalSpacing="5dp"
    android:stackFromBottom="true" />

并使用了这个属性android:stackFromBottom="true"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-17
    • 2022-12-11
    • 2014-12-21
    • 1970-01-01
    • 2020-12-28
    • 2020-01-16
    • 1970-01-01
    • 2021-08-18
    相关资源
    最近更新 更多