Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 419
android developer Avatar asked Mar 12 '17 09:03

android developer


1 Answers

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

like image 175
Okas Avatar answered Oct 13 '22 09:10

Okas