在 edittext 中输入增加其 space 并减少其他 edittext space

Typing in edittext increase its space and decreases the other edittext space

我有一个带有两个文本视图和两个编辑文本的线性布局。问题是每当我开始在任何 editText 中书写时,另一个 editText 在 space 中开始变小,并且随着输入的进行,聚焦的 editText space 会增加。

我的XML代码是:

   <LinearLayout
                android:id="@+id/l6"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/l5"
                android:layout_margin="10dp"
                android:orientation="horizontal"
                android:padding="2dp"
                android:weightSum="4">

                <TextView
                    android:id="@+id/txtOverAddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.2"
                    android:text="Oversease Address: " />

                <EditText
                    android:id="@+id/edtOverAddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="12sp"
                    android:layout_weight="2.6"
                    android:inputType="text"
                    android:padding="5dp" />

                <TextView
                    android:id="@+id/txtReffBy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_weight="0.2"
                    android:text="Reffered By: " />

                <EditText
                    android:id="@+id/edtReffBy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textSize="12sp"
                    android:inputType="text"
                    android:padding="5dp" />

            </LinearLayout>

我不知道我哪里做错了。需要帮忙!提前致谢。

如果您可以设置 android:layout_weight 那么根据线性布局方向您可以设置 android:layout_width="0dp"

   <LinearLayout
                android:id="@+id/l6"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/l5"
                android:layout_margin="10dp"
                android:orientation="horizontal"
                android:padding="2dp"
                android:weightSum="4">

                <TextView
                    android:id="@+id/txtOverAddress"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.2"
                    android:text="Oversease Address: " />

                <EditText
                    android:id="@+id/edtOverAddress"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:textSize="12sp"
                    android:layout_weight="2.6"
                    android:inputType="text"
                    android:padding="5dp" />

                <TextView
                    android:id="@+id/txtReffBy"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_weight="0.2"
                    android:text="Reffered By: " />

                <EditText
                    android:id="@+id/edtReffBy"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textSize="12sp"
                    android:inputType="text"
                    android:padding="5dp" />

            </LinearLayout>

在权重和为 4 的父线性布局中创建权重为 2 的两个线性布局。之后,您在宽度为 0 dp 的每个线性布局中创建 textview 和 edittext。

我对你的代码做了一些改动,但我不确定你的要求是什么 1. 如果文本超出了Edittext的宽度,是否要将文本移到下一行? 2.或者超过Edittext的宽度是否要水平滚动?

给出的 EditText 中的两件事我都做了。第一个移动到新行,第二个将滚动

<LinearLayout android:id="@+id/l6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/l5"
android:layout_margin="10dp"
android:orientation="horizontal"
android:padding="2dp"
android:weightSum="4"
xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:id="@+id/txtOverAddress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.2"
        android:text="Oversease Address: " />

    <EditText
        android:id="@+id/edtOverAddress"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:layout_weight="2.6"
        android:text="Hello I am doing good. Hope you are also doing well"
        android:inputType="textMultiLine"
        android:padding="5dp" />

    <TextView
        android:id="@+id/txtReffBy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_weight="0.2"
        android:text="Reffered By: " />

    <EditText
        android:id="@+id/edtReffBy"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="12sp"
        android:inputType="text"
        android:text="Hello I am doing good. Hope you are also well"
        android:padding="5dp" />

</LinearLayout> 

希望这会有所帮助。