如果将orientation的vertical设置成horizontal则会变成水平排列,如下图显示
可以使用layout_weight属性来设置每行控件的相对大小
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:orientation=“horizontal” android:layout_width=“match_parent”
android:layout_height=“wrap_content”>
<Button
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:text=“按钮1”/>
<Button
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:text=“按钮2”/>
<Button
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:text=“按钮3”/>
在layout_weight中我们设置它的占据权重为1,则总的权重为1+1+1=3,所以每个控件的所占大小就会是1/3,就会平均分掉这一行的布局。那当我们将其中一个控件的权重修改为2时,就会显示下图的结果。他们的权重比就会是1/4、1/4、2/4。