本文介绍了将RecyclerView配置为聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

To enable chat-style scrolling in a List View, we can use the following properties:

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ....
    android:stackFromBottom="true"
    android:transcriptMode="normal" />

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

It is a simple and efficient way to create a chat.How can we do the same thing with a recycler view ? I did not find any simple solution.

关于

推荐答案

RecyclerView具有stackFromEnd属性.

RecyclerView has a stackFromEnd attribute.

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

或者您可以通过代码完成

Or you can do it through code

mLayoutManager = new LinearLayoutManager(getActivity());
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);

这篇关于将RecyclerView配置为聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:33