Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am new to android development and I am struggling with something simple which I just cannot figure out.

WHAT I WANT:
I basically want my EditText and "Send" button to be shifted up the screen above the keyboard when the user taps on the EditText to enter a message. This is working fine and when the user taps the EditText, the keyboard displays and the EditText and Button is stuck to the top of the keyboard as it should be. However, I still want the rest of my layout to be scrollable, because now the EditText and Button is overlapping other elements on the layout and the View cannot be scrolled. For instance, my EditText is overlapping a Spinner, and for the user to select something from the Spinner, he needs to first hide the keyboard again. I want him to be able to just scroll the view in order to select from the spinner without having to close the keyboard.

I hope it is clear what I am trying to do. Here is my XML code for my layout.

XML
<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="za.co.mincdevelopment.mincsmsconsole.SendSingle">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:id="@+id/scrollView">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="@string/message_heading"
                android:id="@+id/txtSendSingleHeading"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"/>

            <View
                android:layout_width="fill_parent"
                android:layout_height="2dp"
                android:layout_marginTop="5dp"
                android:removed="#00baff"
                android:layout_below="@+id/txtSendSingleHeading"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:id="@+id/viewLogin" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="phone"
                android:ems="10"
                android:id="@+id/edtRecipient"
                android:layout_below="@+id/txtSendSingleHeading"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginTop="46dp"
                android:drawableLeft="@drawable/cell"
                android:drawableStart="@drawable/cell"
                android:hint="@string/text_number_recipient"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true" />

            <!-- Spinner Dropdown -->
            <Spinner
                android:id="@+id/spinTemplate"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:prompt="@string/spinner_title"
                android:layout_marginTop="25dp"
                android:layout_below="@+id/edtRecipient"
                android:layout_centerHorizontal="true" />

        </RelativeLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:weightSum="1">
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/edtMessage"
            android:inputType="textMultiLine"
            android:removed="@drawable/edittext_custom"
            android:maxLength="160"
            android:padding="8dp"
            android:hint="@string/text_write_message"
            android:layout_weight="1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_send"
            android:id="@+id/btnSend"
            android:drawableLeft="@drawable/send_icon"
            android:drawableStart="@drawable/send_icon"
            android:padding="8dp"
            android:background="?attr/selectableItemBackground"/>

    </LinearLayout>
</RelativeLayout>
Posted
Comments
Richard MacCutchan 16-Sep-15 15:28pm    
What happens if you put the Button and Edit text above the ScrollView?
Christopher Smit 16-Sep-15 15:33pm    
Okay, the screen is now scrollable, but only up until the keyboard. I cannot scroll the elements from under the EditText and the Button. So I am scrolling it but it stays under the EditText and Button. I think I have this entire layout wrong.
Krunal Rohit 17-Sep-15 0:52am    
In ScrollView, use the LinearLayout and place your inside it.

-KR
Christopher Smit 17-Sep-15 15:18pm    
I am able to scroll using the LinearLayout, however I cannot scroll all the way to the bottom so some elements are still hidden?

Is there a way to maybe fix the LinearLayout of the EditText and Button to the screen so everything is able to scroll from under it? I do not really know how to ask this question? All I know is the elements are able to scroll until where the keyboard ends, but then the element that is at the bottom is still under the EditText and Button (But scrolled from under the keyboard.)
Krunal Rohit 18-Sep-15 3:24am    
I'm sorry but not getting you.

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900