android developer android developer - 9 months ago 25
Android Question

Is it possible to reverse the order of views being laid out in a vertical LinearLayout?

By default, views in a vertical LinearLayout are measured and layouts from top to bottom, just as on horizontal one from left to right.

Usually, if I want to have a layout that has its children measured from bottom to top, I usually use RelativeLayout, with an id for each of the children, while the bottom view has layout_alignParentBottom set to true, and the rest have "layout_above" set to the view below them:

<RelativeLayout>
<View android:id="@+id/bottomView android:layout_alignParentBottom="true" />

<View android:id="@+id/secondView android:layout_above="@+id/bottomView " />

<View android:id="@+id/thirdView android:layout_above="@+id/secondView " />

...
</RelativeLayout


But this is annoying to set, and can have issues if being added into another layout.

Is it possible to have this behavior on LinearLayout? The only thing I've found is LayoutDirection, but this seems to belong to RTL direction (horizontal), so it doesn't work.

Answer Source

Just set android:gravity="bottom" for your LinearLayout.