linelayout这个布局有一个特别的属性,就是权重
别的布局没有
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="wei"
android:textAllCaps="false"
android:textColor="#ff0000"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="wei"
android:textAllCaps="false"
android:textColor="#ff0000"
android:layout_weight="1"/>
</LinearLayout>
权重android:layout_weight表示占得百分比
比如这两个button weight都是1,那么两个占得就是50%
设置权重之后,肯定会铺满某个方向的屏幕,比如linelayout设置为水平的话,那么久铺满水平的屏幕,如下图所示
这就是权重weight。