0
更新問題:我知道LinearLayout更好,並且已經使用線性實現。 我有一個教育任務,需要RelativeLaouyt實施。 請不要評論線性佈局,這不是我的問題的目的。如何在Android的RelativeLayout中爲3個按鈕設置相同的寬度?
我知道在LinearLayout中它更容易,但我必須僅使用RelativeLayout來實現它。 我有我的xml文件中的3個按鈕,並希望他們在同一行,並具有相同的寬度,等於屏幕的1/3。
(我發現here使用一個「假」視圖按鈕一個很好的解決方案,但它並不適用於3個按鈕的工作。)
任何想法? (相對佈局而已!)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10dp">
<Button
android:id="@+id/bottom_left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Left"/>
<Button
android:id="@+id/bottom_center"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_centerInParent="true"
android:text="Center"/>
<Button
android:id="@+id/bottom_right"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_alignParentRight="true"
android:text="Right"/>
</RelativeLayout>
您可以隨時以編程方式添加它們並計算寬度。 –
雖然相對比線性佈局更好。你可以做一個線性的,然後給每個按鈕一個均勻的重量 – Phil3992
任何原因爲**固執**不使用'LinearLayout'?每個佈局都是爲了某個目的而製作的,如果您不將它們用於其目的,那麼您的UI將不會被優化。 –