我有LinearLayout(视频按钮容器)和图像按钮,因为它是孩子。我想让那个视频按钮对齐,所以我给了它layout_gravity="right"
。Android线性布局方向如何影响布局引力?
<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>
它产生这样的:
我想是这样的:
我也得到通过改变视频按钮容器的android:orientation="horizontal"
到android:orientation="vertical"
。 发生了什么?为什么它不适用于容器的水平方向?
嗨! orientation属性做了什么?当我从“垂直”状态转换为“水平状态”时,我的布局没有发现任何不同...谢谢! –