Android edittext automatically grows with text and pushes things down

Yes, this is another question regarding SO. And yes, I have already gone through all these editorial issues. But this is a little specific.

UI:

enter image description here

Simple Android layout with edittext button and button below. When the text is smaller, the edittext view still covers the entire screen, leaving room for the button below.

As the user begins to enter text, edittext grows vertically to accommodate the text. At the same time, the button should also continue to push down to increase the edittext.

The user can vertically scroll the screen to view the full text.

User interface after entering meaningful text:

enter image description here

Here's the layout with edittext and button below:

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background" android:clipToPadding="false" android:fadingEdge="none" android:fillViewport="true" android:padding="13dp" android:scrollbarStyle="outsideOverlay" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"> <!-- some fixed width image --> <ImageView android:id="@+id/someimage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:src="@drawable/page_white_text" /> <EditText android:id="@+id/some" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/someimage" android:background="@null" android:gravity="top" android:minLines="10" android:minHeight="50dp" android:textColor="#222222" android:textSize="15dp" android:typeface="serif" > <requestFocus /> </EditText> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:baselineAligned="true" android:layout_marginTop="5dp" android:padding="10dp" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> </RelativeLayout> </ScrollView> 

It works more or less. But when I enter the big text, instead of pushing the button down. He follows him as:

enter image description here

Any help here is much appreciated. Thanks:)

+6
source share
3 answers

Here is my recommendation: inside the ScrollView, put a RelativeLayout in which you can place each element in a specific order using android: layout_below. To automatically grow your EditText, use this solution .

Let's look at an example:

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center"> <RelativeLayout android:id="@+id/general2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="20sp" > <TextView android:id="@+id/textFirstOpinion" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/titleFirstOpinion" android:textStyle="bold" android:textSize="23sp" android:textColor="#FFFFFF" android:layout_marginTop="10dp" /> <EditText android:id="@+id/fieldFirstOpinion" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/textFirstOpinion" android:minHeight="80sp" android:isScrollContainer="true" android:inputType="textMultiLine" android:textSize="20sp" android:gravity="top|left" /> <Button android:id="@+id/button" android:layout_width="110dp" android:layout_height="wrap_content" android:layout_below="@id/fieldFirstOpinion" android:layout_centerHorizontal="true" android:layout_marginTop="37sp" android:textSize="23sp" android:text="@string/textSendButton" android:gravity="center_horizontal" android:padding="10dp" /> </RelativeLayout> </ScrollView> 
+2
source

try adding android: layout_below = "@ id / some" to your LinearLayout, for example

  <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:baselineAligned="true" android:layout_marginTop="5dp" android:padding="10dp" android:orientation="vertical" android:layout_below="@id/some" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> 
0
source

Since you want the button to be at the bottom of the page, add the following line

 android:layout_below="@+id/some" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" 

in your LinearLayout code here for example

  <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/some" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:baselineAligned="true" android:layout_marginTop="5dp" android:padding="10dp" android:orientation="vertical" > 

Also make sure that the layout:height parameter of the EditText parameter is set to wrap_content Try this and tell me if this works or not.

0
source

All Articles