Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure RecyclerView to work as a chat

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.

Regards,

like image 428
insane.bot Avatar asked Jun 04 '15 04:06

insane.bot


People also ask

Does WhatsApp use RecyclerView?

In order to display a list in your application, we all must have used RecyclerView in Android. For example, the emails in the Gmail app, the feeds on Facebook and Instagram, messages in WhatsApp, all are done with the help of RecyclerView.

What is the difference between RecyclerView and CardView?

The RecyclerView is a more advanced and more flexible version of the ListView. This new component is a big step because the ListView is one of the most used UI widgets. The CardView widget, on the other hand, is a new component that does not “upgrade” an existing component.

What is RecyclerView LayoutManager?

A RecyclerView.LayoutManager implementation that lays out items in a grid for leanback VerticalGridView and HorizontalGridView . LinearLayoutManager. A RecyclerView.LayoutManager implementation which provides similar functionality to ListView .


2 Answers

add these statements;

<android.support.v7.widget.RecyclerView
                    android:id="@+id/chat_list_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:drawSelectorOnTop="false"
                    android:listSelector="@android:color/transparent"
                    android:paddingLeft="4dp"
                    android:paddingRight="4dp"
                    android:scrollbarStyle="outsideOverlay"
                    android:transcriptMode="normal" />

and add into layout manager

layoutManager.setStackFromEnd(true);
like image 61
Abdul Rizwan Avatar answered Sep 16 '22 16:09

Abdul Rizwan


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);
like image 31
Bidhan Avatar answered Sep 20 '22 16:09

Bidhan