是否可以颠倒在垂直 LinearLayout 中布局的视图顺序?

and*_*per 5 android android-layout android-linearlayout

默认情况下,垂直 LinearLayout 中的视图是从上到下测量和布局的,就像水平视图从左到右一样。

通常,如果我想要一个布局从下到上测量它的孩子,我通常使用RelativeLayout,每个孩子都有一个id,而底部视图的layout_alignParentBottom设置为true,其余的有“layout_above”设置为它们下面的视图:

<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
Run Code Online (Sandbox Code Playgroud)

但这设置起来很烦人,如果添加到另一个布局中可能会出现问题。

是否有可能在 LinearLayout 上有这种行为?我唯一发现的是LayoutDirection,但这似乎属于RTL方向(水平),所以它不起作用。

Oka*_*kas 3

只需为您的 LinearLayout 设置 android:gravity="bottom" 即可。