Question

I'm making an android app in which there's an activity having an EditText on the top and three Buttons at the bottom. I've set android:windowSoftInputMode="adjustResize" in my manifest to activity so that it gets re-sized automatically when the virtual keyboard is being used. But, as I type in a long sentence in the EditText, it's size increases and it goes beneath the Buttons. I want the EditText to expand only upto the free space between the 3 Buttons and the ActionBar.

Here's what's happening -

error_scrennshot

Here's the XML code of the activity -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eaeaea"
    tools:context=".AddNoteEditor" >

<EditText
    android:id="@+id/noteEditor"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:background="@drawable/card"
    android:ems="10"
    android:hint="@string/nn"
    android:inputType="textMultiLine"
    android:padding="12.5dp"
    android:singleLine="true"
    android:textSize="19dp" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClickAddNote"
    android:text="@string/ok"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" />

<ToggleButton
    android:id="@+id/highlighter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_toLeftOf="@+id/button2"
    android:layout_toRightOf="@+id/button1"
    android:text="@string/hglt"
    android:textOff="Highlighting Off"
    android:textOn="Highlighting On" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClickDiscardNote"
    android:text="@string/cancel"
    android:layout_alignTop="@+id/highlighter"
    android:layout_alignParentRight="true" />

</RelativeLayout>

Thanks in Advance.

Was it helpful?

Solution

The problem is with the Relative Layout, in which EditText fills up the entire available space (in this layout) when text is long enough. As a result it fills also the space that is under those buttons.

You have basically two solutions.

  1. Add a bottom margin to your EditText that will be equal in size to the height of a button.

  2. Use Linear Layout(s) instead of Relative Layout (one Linear Layout to replace the Relative Layout - a vertical one, and another Linear Layout - horizontal - to place those buttons side by side).

OTHER TIPS

maybe you must try your EditText as scrollable:

for horizontal scroll:

 <EditText
      android:scrollHorizontally="true"
 ../>

for vertical scroll:

<EditText
     android:scrollbars = "vertical"
../>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top