Android Linearlayout重量怪异

Android Linearlayout重量怪异,android,android-layout,Android,Android Layout,我对这个简单的布局有问题: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/editText1" android:la

我对这个简单的布局有问题:

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

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="10"
            android:ems="10"
            android:hint="Title" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="45"
            android:ems="10"
            android:hint="First Name" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="45"
            android:ems="10"
            android:hint="Last Name" />

    </LinearLayout>

如您所见,这应该将屏幕分割为10-45-45,但布局如下所示:

这似乎只是编辑文本的问题

给你-

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

    <EditText
        android:id="@+id/editText1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:ems="10"
        android:hint="Title" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="45"
        android:ems="10"
        android:hint="First Name" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="45"
        android:ems="10"
        android:hint="Last Name" />

</LinearLayout>

我将
android:layout\u width
设置为0dp。使用权重时,如果使用水平方向的线性布局,则需要将
android:layout\u width
设置为0dp,如果方向为垂直方向,则需要将
android:layout\u height
设置为0dp,以便权重生效。希望有帮助。

只要使用

android:layout_width="0dp"
而不是

android:layout_width="wrap_content"

使用权重时,应将视图的宽度设置为0dp。另外,android:ems可能会影响重量。谢谢,没想到这会解决这个问题。:)