android:layout_weight 使用

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
              android:layout_centerHorizontal="true"
              android:gravity="center_horizontal"
        android:layout_below="@+id/linearLayout4"
        android:weightSum="2"
        android:layout_marginTop="40dp" >

        <Button
            android:id="@+id/btn_regist"
      android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="@string/regist" />

        <Button
            android:id="@+id/btn_login"
              android:layout_width="wrap_content"
              android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="@string/login" />
    </LinearLayout>


父容器 声明android:weightSum 

子对象 声明android:layout_weight

子对象会自适应父容器大小。如下效果图,注意底部button的尺寸

竖屏时的效果

android:layout_weight 使用_第1张图片


横屏效果

android:layout_weight 使用_第2张图片


你可能感兴趣的:(android:layout_weight 使用)