Configure RecyclerView for live chat

To enable chat style scrolling in the 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" /> 

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

Yours faithfully,

+6
source share
3 answers

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 with code

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

add this two lines in xml

 app:stackFromEnd="true" app:reverseLayout="true" 
+1
source

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 to the layout manager

 layoutManager.setStackFromEnd(true); 
0
source

Source: https://habr.com/ru/post/988491/


All Articles