EditText溢出到按钮中

EditText overflowing into button

我的片段 activity 中有一个 EditText 和一个 Button

我面临两个问题。

1) 我不能把 Button 放在 EditText.

的正下方

这里是截图:

2) 每当我在 EditText 中粘贴冗长的文本时,按钮就会与文本重叠。请看截图。

这是我的 XML :

      <FrameLayout>

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:text="@string/URL"
            android:hint="@string/hint"
            android:layout_marginTop="200dp"
            android:layout_gravity="center_horizontal|top" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Track"
            android:id="@+id/button"
            android:layout_gravity="center"
            />

       </FrameLayout>

如何解决问题。有什么帮助吗?

使用 RelativeLayout 或 LinearLayout 而不是 FrameLayout。 FrameLayout 的目的是显示一个项。

您可能想考虑使用 RelativeLayout,而不是使用 FrameLayout。然后您可以执行以下操作:

对于 EditText,使用以下属性:

// This says the widget should be vertically and horizontally at the center of the container
android:layout_centerInParent="true"

对于按钮,使用以下属性:

android:layout_below:"@id/editText"

我提到的属性将替换

android:layout_gravity

您使用过的两个小部件的属性。

EditText 也会丢失

android:layout_marginTop="200dp"

属性,因为 layout_centerInParent 属性会自动将其居中。

这是伪代码,但可以帮助您理解结构

<RelativeLayout>

    <LinearLayout
    orientation=vertical
    centerInParent= true
    >

       <EditText/>
       <Button/>
    </LinearLayout>

 </RelativeLayout>