android – RecyclerView stackFromBottom-ThrowExceptions

Exception or error:

I just implemented the new RecyclerView. I want to use it do display user’s messages(sms).

I read on official documentation that RecyclerView is a new and improved ListView (something like that) and we should use it for better performance.

Everything went great until I wanted to display a user’s conversation and I want the messages to be displayed starting from the bottom. In a ListView I would normally use android:stackFromBottom="true" but when I tried this in the RecyclerView it didn’t work (even if didn’t receive any error).

Does anyone know how to make the RecyclerView‘s items to be stacked from bottom? Thank you.

How to solve:

Making it a little explicit:

   final LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
   layoutManager.setStackFromEnd(true);
   recyclerView.setLayoutManager(layoutManager);

###

Thanks to tyczj’s comment I figured it out. In RecyclerView instead of stackFromBottom you have to use stackFromEnd https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#setStackFromEnd(boolean)

Leave a Reply

Your email address will not be published. Required fields are marked *