Make Recycler View show rows from bottom
Here is the solution in Kotlin
val llm = LinearLayoutManager(this)
llm.stackFromEnd = true // items gravity sticks to bottom
llm.reverseLayout = false // item list sorting (new messages start from the bottom)
rv_chat_history.layoutManager = llm
Or if you like the apply method:
recycler.apply {
layoutManager = LinearLayoutManager(this).apply {
stackFromEnd = true
reverseLayout = false
}
}
If you are using LinearLayoutManager make third param (reverseLayout) false
LinearLayoutManager linearLayoutManager =
new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
You can achieve this task by adding two lines to the xml code.
app:stackFromEnd="false"
app:reverseLayout="true"
This will work as all chat apps.
Is it LinearLayoutManager.setStackFromEnd(true)
you are looking for?
Edit
Turns out LinearLayoutManager.setReverseLayout(true)
does the trick. Either way, the reader may want to try each of the methods and the combination of both to get the needed effect.