线性布局:主要以水平或垂直的方式来显示界面中的控件
1.控件的排列方向为水平:
android:orientation="horizontal"
2.控件的排列方向为垂直
android:orientation="vertical"
注意:
1.当控件水平排列时,控件属性Layout_width 只能设置为wrap_content(包裹内容,让当前控件根据控件内容大小自动收缩),否则其余控件会被挤出屏幕右侧不被显示。同理,控件垂直排列也会出现这个现象。
android:layout_width="wrap_content"
2.控件水平排列时,如果控件未占满一行,会留有空白区域,既不美观,又浪费。可以利用layout_weight属性解决这个问题,该属性称为权重,通过比例调整布局中所有控件的大小;(使用权重属性时,通常把Layout_width属性设置成"0dp")
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />