Android 使用布局权重

Android 使用布局权重,android,android-layout,Android,Android Layout,为什么中间的按钮会消失?而不是拉伸以填充其父对象的所有宽度?而当我设置layout_height=0dp时,它会用高度填充它们的父对象 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >

为什么中间的按钮会消失?而不是拉伸以填充其父对象的所有宽度?而当我设置layout_height=0dp时,它会用高度填充它们的父对象

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"        
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Button" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:text="TextView" />


由于线性布局方向是垂直的,因此如果布局权重为“1”,则只占用剩余高度,此处的方向是关键。如果要共享宽度,可以将方向更改为“水平”。请记住,此时您的孩子将被水平放置。

由于线性布局方向是垂直的,如果布局权重为“1”,则只有剩余的高度将被占用,此处的方向是关键。如果要共享宽度,可以将方向更改为“水平”。请记住,您的孩子将被水平放置。

您可以按照您的意愿在此处绘制图片并上传图像吗?您可以按照您的意愿在此处绘制图片并上传图像吗?