Linearlayoutmanager Setreverselayout() == True But Items Stack from Bottom

LinearLayoutManager setReverseLayout() == true but items stack from bottom

from the docs for setReverseLayout

Used to reverse item traversal and layout order. This behaves similar to the layout change for RTL views. When set to true, first item is laid out at the end of the UI, second item is laid out before it etc. For horizontal layouts, it depends on the layout direction. When set to true, If RecyclerView is LTR, than it will layout from RTL, if RecyclerView} is RTL, it will layout from LTR. If you are looking for the exact same behavior of setStackFromBottom(boolean), use setStackFromEnd(boolean)

So, try also using setStackFromEnd(boolean) on your LinearLayoutManager instance,

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

Display RecyclerView items starting from bottom without reversing the order

It seems like you should be using setStackFromEnd(true), not setReverseLayout(true).

setReverseLayout(true) reverses the order of your items - Test message 1 would appear as the last item, rather than the first. This is why you get the order of 3, 2, then 1 - you've just reversed your list. This would be what you'd want if Test message 1 was your most recent message, which doesn't seem to be the case for you.

setStackFromEnd(true), on the other hand, effectively just stacks your items in the same order you give them in from the bottom up. This is why Test message 3 appears at the bottom with 2 above it and 1 above it. This is appropriate if you just want items to visually be stacked up from the bottom in the exact order you provide.

Make Recycler View show rows from bottom

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.

Recyclerview reverse layout starting scroll position issue

this is very easy you have to add only single line :-

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);

Android reverse recylcerview

You haven't posted any Java code. So try this:

Set this LayoutManager to the RecyclerView.

recyclerView.setLayoutManager(new LinearLayoutManager(context, VERTICAL, true)); 

How to enable new data display at top in RecyclerView by default?

You can achieve the same by

LinearLayoutManager mLayoutManager = new LinearLayoutManager(MainActivity.this);
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
// And now set it to the RecyclerView
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(yourAdapter);


Related Topics



Leave a reply



Submit