Android线性布局方向如何影响布局重力?

Mil*_*lan 1 android android-layout

我有LinearLayout(视频按钮容器)和图像按钮作为它的孩子.我希望视频按钮正确对齐,所以我给了它layout_gravity="right".

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <!-- VIDEO BUTTON CONTAINER -->
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#000000"
        android:layout_gravity="top">

        <!-- VIDEO BUTTON -->
        <ImageButton
            android:id="@+id/button_video"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:background="?android:attr/selectableItemBackground"
            android:contentDescription="@string/desc"
            android:paddingBottom="@dimen/controls_button_padding"
            android:paddingTop="@dimen/controls_button_padding"
            android:src="@drawable/ic_action_video" />
    </LinearLayout>

    <!-- some FrameLayout and another LinearLayout -->
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

它产生了这个:

在此输入图像描述

我想要的是这个:

在此输入图像描述

我通过改变视频按钮容器android:orientation="horizontal"来实现android:orientation="vertical".发生了什么?为什么它不适用于容器的水平方向?

Ame*_*een 8

如果容器是水平的,则应该按顺序从左到右堆叠元素.现在,如果是这样的话,它如何在保持原有前提的同时水平满足布局重力?

水平重力(右,左,中)将在垂直LinearLayout中工作,垂直重力(上,下)将在水平LinearLayout中工作.