RecyclerView Grow Element From Right to Left

Found out how to do it, all you have to do is set

linearLayoutManager.setStackFromEnd(true);

  LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                linearLayoutManager.setStackFromEnd(true);

You can add it directly from XML by adding the app:reverseLayout attribute:

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layoutManager="android.support.v7.widget.LinearLayoutManager"
    app:layout_constraintEnd_toStartOf="@+id/imageButton2"
    app:layout_constraintTop_toTopOf="@+id/imageButton2"
    app:reverseLayout="true"
    tools:listitem="@layout/images_new_post_item" />

Just use this :

android:layoutDirection="rtl"

that's all :)


it is pretty simple, just call setReverseLayout(true) for your LayoutManager :

LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true);
        layoutManager.setReverseLayout(true);

it is explained in its documentation :

 /**
 * 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 {@link android.support.v7.widget.RecyclerView} is LTR, than it will
 * layout from RTL, if {@link android.support.v7.widget.RecyclerView}} is RTL, it will layout
 * from LTR.
 *
 * If you are looking for the exact same behavior of
 * {@link android.widget.AbsListView#setStackFromBottom(boolean)}, use
 * {@link #setStackFromEnd(boolean)}
 */
public void setReverseLayout(boolean reverseLayout) {
    assertNotInLayoutOrScroll(null);
    if (reverseLayout == mReverseLayout) {
        return;
    }
    mReverseLayout = reverseLayout;
    requestLayout();
}