将 RecyclerView 配置为聊天 [英] Configure RecyclerView to work as a chat

查看:24
本文介绍了将 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 配置为聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆