Nikhil
Nikhil

Reputation: 6641

EditText overflowing into button

I have an EditText and a Button in my fragment activity.

I'm facing two issues.

1) I cannot put the Button, exactly below the EditText.

Here, is the screenshot :

enter image description here

2) Whenever I paste lengthy text in the EditText, button is overlapping with the text. See this screenshot:

enter image description here

Here is my 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>

How can I solve the issue?

Upvotes: 0

Views: 39

Answers (3)

Suhail Mehta
Suhail Mehta

Reputation: 5542

This is pseudo code but help you to understand the structure

<RelativeLayout>

    <LinearLayout
    orientation=vertical
    centerInParent= true
    >

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

 </RelativeLayout>

Upvotes: 1

ucsunil
ucsunil

Reputation: 7494

Instead of using a FrameLayout, you might want to consider using a RelativeLayout. Then you can do the following:

For the EditText, use the following attribute:

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

For the Button, use the following attribute:

android:layout_below:"@id/editText"

The attributes that I have mentioned will replace the

android:layout_gravity

attributes for both the widgets you have used.

Also the EditText will lose the

android:layout_marginTop="200dp"

attribute as the layout_centerInParent attribute will automatically center it.

Upvotes: 1

Jenthe
Jenthe

Reputation: 797

Use RelativeLayout or LinearLayout instead of FrameLayout. The purpose of FrameLayout is to display one item.

Upvotes: 1

Related Questions