2017-08-01 180 views
0

我加入佈局管理到recyclerview的XML代碼:Android的設置setReverseLayout爲RecyclerView佈局管理

messagesView.getLayoutManager().setReverseLayout(true); 

在這種情況下,我不:

<android.support.v7.widget.RecyclerView 
       android:id="@+id/messagesView" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> 

現在我不能用這個代碼中設置setReverseLayout喜歡通過Java代碼來設置Layoutmanager

回答

0

使用app:reverseLayout="true"

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.RecyclerView android:id="@+id/transcript" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layoutManager="LinearLayoutManager" 
    app:reverseLayout="true" 
    app:stackFromEnd="true" /> 

(來自this sample appthis book