LinearLayout中使每個子控制元件均勻佈局
阿新 • • 發佈:2019-02-02
要想使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>