I am having a hard time debugging a very simple problem. I have a layout of an activity where there is an EditText
and a button below the EditText
to do an operation. The problem is, I was typing long sentences into the EditText
, it used to grow in height and the button was pushed beneath the screen. Here is my layout file:
<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="#231f20">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FAC80A"
android:elevation="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView176"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:src="@drawable/cta_ic_notifications_grey" />
<TextView
android:id="@+id/textView109"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Help"
android:textColor="#231f20"
android:textSize="20sp" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<TextView
android:id="@+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="60dp"
android:alpha="0.8"
android:text="We are here to help! We have recently launched the app and it is in beta. Not all features may be working in an optimal manner.In the meantime, if you have any feedback, or if there is any help you need, please reach out to us:"
android:textColor="#FFFFFF"
android:textSize="17sp" />
<ImageView
android:id="@+id/imageView50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:layout_marginBottom="70dp"
android:src="@drawable/help_contact_button_send_in_active" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_above="@+id/imageView50"
android:layout_below="@+id/textView22">
<EditText
android:id="@+id/editText10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="How can we help you today?"
android:inputType="textCapSentences|textMultiLine"
android:textColor="#FFFFFF"
android:textColorHint="#707070"
android:theme="@style/EditTextStyle" />
</ScrollView>
</RelativeLayout>
What I want is, the send button should always be visible at bottom and no matter how long sentences I type into the EditText
, it should scroll and be constrained between the header TextView
and ImageView
button. In this particular layout, as soon as I start typing, the send button comes on top and I am not able to see anything I type, it is only after closing the keyboard, that I am able to see the text and send button below it.
Inside scrollview you are using Edittext and scrollview has height wrap_content, that is why it is happening. to solve this problem you can remove the scrollview and define the editText like this
<EditText
android:id="@+id/add_task_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-bold"
android:hint="Notes"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="5"
android:scrollbars="vertical"
android:textColor="@color/edit_text_color"
android:textSize="@dimen/edit_text_font_size"></EditText>
this Edittext will give the scrollable text and maximum visible lines
If you want to make the whole layout scrollable then make ScrollView as your parent layout