(笔记)Android studio——layout-weight()


将layout_width设为0,系统就会先将LinearLayout下所有控件指定的layout_weight相加得到一个总值,然后每个控件所占的比例就是用该控件的layout_weight值除以刚才算出的总值

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="请输入密码"
        android:textSize="23dp" />
<Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/bt5"
    android:text="确定"
    />
LinearLayout>



运行截图


(笔记)Android studio——layout-weight()_第1张图片


你可能感兴趣的:((笔记)Android studio——layout-weight())