【问题标题】:Android set setReverseLayout for RecyclerView LayoutManagerAndroid为RecyclerView LayoutManager设置setReverseLayout
【发布时间】:2017-08-02 02:36:08
【问题描述】:

我在 xml 代码上添加了 layoutmanager 到 recyclerview:

<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

messagesView.getLayoutManager().setReverseLayout(true);

在这种情况下,我不喜欢通过 java 代码设置 Layoutmanager

【问题讨论】:

    标签: android


    【解决方案1】:

    使用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 app来自this book

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多