RecyclerView stackFromBottom

2019-01-18 20:10发布

问题:

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.

回答1:

Making it a little explicit:

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


回答2:

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)