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

    <TextView
        android:id="@+id/tv_label_client_host"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="@string/label_host" />
    <EditText
        android:id="@+id/et_client_host"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:inputType="text"
        android:layout_weight="1.0"
        android:lines="1" />
</LinearLayout>

我希望EditText通过水平填充剩余的整个空间,但TextView获得EditText可用空间的 1/2。这LinearLayout是放置在另一个垂直的内部LinearLayout

4

5 回答 5

1

去除那个

   android:ems="10"

对于所有元素,我在这里进行了测试并且它有效。

于 2012-10-04T12:20:47.497 回答
0

将 TextView 的宽度设置为 0dp....

于 2012-10-04T12:15:20.887 回答
0
<LinearLayout android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:weightSum="1"
>

    <TextView
        android:id="@+id/tv_label_client_host"
        android:layout_weight="0"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="@string/label_host" />
    <EditText
        android:id="@+id/et_client_host"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:inputType="text"
        android:layout_weight="1"
        android:lines="1" />
</LinearLayout>
于 2012-10-04T12:24:26.963 回答
0

您必须为布局中的每个组件赋予权重。这样,它就会知道每个人的重量。所以你可以试试这个:

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

    <TextView
        android:id="@+id/tv_label_client_host"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_weight="0.3"
        android:text="@string/label_host" />
    <EditText
        android:id="@+id/et_client_host"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:inputType="text"
        android:layout_weight="0.7"
        android:lines="1" />
</LinearLayout>
于 2012-10-04T12:26:40.960 回答
0

如果可能的话,android:ems="10"从 TextView 中删除并将 TextView 的权重添加到android:layout_weight="0"

于 2012-10-04T12:28:34.483 回答