

<?xml version="1.0" encoding="utf-8"?>
<!--
android:layout_width="match_parent"
计算出的宽度 = 原来宽度 + 剩余空间中其所占百分比宽度
2/3L = L + (L - 2L) * 1/3 = L - 1/3L = 2/3L
android:layout_width="0dp"
就会按照比例进行拉伸
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<!--
android:layout_width="0dp"
就会按照比例进行拉伸
-->
<Button
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button - 1"/>
<!--
android:layout_width="0dp"
就会按照比例进行拉伸
-->
<Button
android:layout_width="match_parent"
android:layout_weight="2"
android:layout_height="wrap_content"
android:text="Button - 2"/>
</LinearLayout>
LinearLayout 中的 layout_weight属性,首先按照控件声明的尺寸进行分配,然后再将剩下的尺寸按weight分配
layout_开头都是交给父容器, 没有layout_开头都是本身的属性