将RecyclerView配置为聊天工作

ins*_*bot 9 android listview android-listview android-recyclerview

要在列表视图中启用聊天式滚动,我们可以使用以下属性:

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ....
    android:stackFromBottom="true"
    android:transcriptMode="normal" />
Run Code Online (Sandbox Code Playgroud)

这是一种创建聊天的简单而有效的方法.我们如何用回收者视图做同样的事情?我没有找到任何简单的解决方案.

问候,

Bid*_*han 17

RecyclerView有一个stackFromEnd属性.

<android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recyclerView" 
        android.support.v7.recyclerview:stackFromEnd ="true"/>
Run Code Online (Sandbox Code Playgroud)

或者你可以通过代码完成

mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
Run Code Online (Sandbox Code Playgroud)