我有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屬性做了什麼?當我從「垂直」狀態轉換爲「水平狀態」時,我的佈局沒有發現任何不同...謝謝! –