我有三個按鈕需要位於屏幕底部的一行。以下是活動xml中的代碼。爲了使三個按鈕佔用空間,我將它們中的每一個都包含在LinearLayout中,並將佈局android:layout_weight
設置爲1和android:layout_gravity
爲中心。如何佈置三個均勻位於LinearLayout下的按鈕?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="90px"
android:background="#88104502"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="@+id/goBack"
android:layout_width="70px"
android:layout_height="80px"
android:gravity="center"
android:background="@drawable/back"
android:onClick="toHomePage" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:id="@+id/findPlant"
android:layout_width="70px"
android:layout_height="80px"
android:gravity="center"
android:background="@drawable/flowr"
android:onClick="toImagePage" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_weight="1">
<Button
android:id="@+id/plantList"
android:layout_width="70px"
android:layout_height="80px"
android:gravity="center"
android:background="@drawable/list" />
</LinearLayout>
</LinearLayout>
但它的按鈕並不位於LinearLayout的中心。下面是截圖:
你可以看到每個按鍵位於的LinearLayout的左側。如何讓他們中心位於?
爲什麼你使用三種不同的線性佈局?它也使用一個主LinearLayout完成,並給予3個按鈕相同的權重。 –