2015-10-18 36 views
1

我使用RecyclerViewGridLayoutManager。在該佈局管理器上,我打電話setReverseLayout(true),以便按相反順序顯示元素。帶GridLayoutManager的RecyclerView和底部的反向佈局堆棧

但是現在,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> 
+0

能你顯示你的XML? –

+2

檢索'getCount() - position - 1'處的項目? – Blackbelt

+0

@MrsEd我將我的佈局添加到了原始帖子中。 @Blackbelt這可以工作。但是,是不是在'Adapter'裏放置了一些'LayoutManager'邏輯? –

回答

-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"