1. 程式人生 > >LinearLayout中使每個子控制元件均勻佈局

LinearLayout中使每個子控制元件均勻佈局

要想使LinearLayout佈局中的每個子控制元件自動設定為相同大小,並均勻分佈,可以在佈局檔案中設定layout_weight引數的值一致。

示例程式碼如下:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/txt_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <TextView
        android:id="@+id/txt_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

</LinearLayout>