2

The question is already asked here. But don't have satisfactory answer, so I am asking again.

I have a scrollable user registration form, and a fixed SignUp button at the bottom of the screen. And i need to show SignUp button at bottom only i.e. It shouldn't be scrollable. I am using RelativeLayout as root container.

My View Hierarchy is:

enter image description here

In case of android:windowSoftInputMode="adjustNothing"

When i tap in any of my EditText then the soft keyboard appears but scrollview is not completely scrollable. Space equivalent to keyboard is gone behind the keyboard. Which i want to make scrollable.

In case of android:windowSoftInputMode="adjustPan"

It works a bit better but not exactly the way i want it. It pushes my whole screen upward including toolbar which is not desired.

In case of android:windowSoftInputMode="adjustResize"

It pushes my button upward which is not required at all.

So, please suggest me a solution which i can use to fulfil my requirement.

Here is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".activities.CreateAccountActivity">

<include
    android:id="@+id/toolbar"
    layout="@layout/app_toolbar" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar"
    android:fillViewport="true"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"><!--android:paddingBottom="@dimen/activity_vertical_margin"-->

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

        <LinearLayout
            android:id="@+id/ll_fields"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <EditText
                android:id="@+id/et_first_name"
                style="@style/create_account_edittext"
                android:hint="@string/first_name" />

            <EditText
                android:id="@+id/et_last_name"
                style="@style/create_account_edittext"
                android:hint="@string/last_name" />

            <EditText
                android:id="@+id/et_dob"
                style="@style/create_account_edittext"
                android:hint="@string/date_of_birth" />

            <EditText
                android:id="@+id/et_email"
                style="@style/create_account_edittext"
                android:hint="@string/email"
                android:inputType="textEmailAddress" />

            <EditText
                android:id="@+id/et_password"
                style="@style/create_account_edittext"
                android:hint="@string/password"
                android:inputType="textPassword" />

            <EditText
                android:id="@+id/et_confirm_password"
                style="@style/create_account_edittext"
                android:hint="@string/confirm_password"
                android:inputType="textPassword" />

            <LinearLayout
                android:id="@+id/ll_terms"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/separator_margin"
                android:background="@color/et_create_account_bg"
                android:orientation="horizontal"
                android:padding="10dp">

                <CheckBox
                    android:id="@+id/cb_terms"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:theme="@style/BrandedCheckbox" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="start"
                    android:text="@string/accept_terms"
                    android:textColor="@color/white"
                    app:font="@string/font_helvetica_normal" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/ll_subscription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/et_create_account_bg"
                android:orientation="horizontal"
                android:padding="10dp">

                <CheckBox
                    android:id="@+id/cb_subscription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:theme="@style/BrandedCheckbox" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="start"
                    android:gravity="center_vertical"
                    android:text="@string/subscription_details"
                    android:textColor="@color/white"
                    app:font="@string/font_helvetica_normal" />

            </LinearLayout>
        </LinearLayout>

        <Button
            android:id="@+id/btn_create_account"
            style="@style/buttonStyle"
            android:layout_alignParentBottom="true"
            android:text="@string/create_account" />

    </RelativeLayout>

</ScrollView>

And my manifest is:

<activity
        android:name=".activities.CreateAccountActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar" />
Safeer
  • 1,407
  • 1
  • 25
  • 29

2 Answers2

0

Just Don't Use

android:windowSoftInputMode

So that by default it will do nothing to adjust when soft keyboard shows... So don't use any of them...

Code Exemple

Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ScrollView"
tools:showIn="@layout/activity_scroll_view">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Your Name..."/>

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Father's Name.."/>

        <EditText
            android:id="@+id/editText3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Mothers's Name.."/>

        <EditText
            android:id="@+id/editText4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Email Address.."/>

        <EditText
            android:id="@+id/editText5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Mobile No.."/>

        <EditText
            android:id="@+id/editText6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Present Address.."/>

        <EditText
            android:id="@+id/editText7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Parmanent Address.."/>

        <EditText
            android:id="@+id/editText8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:hint="Company Name.."/>

        <EditText
            android:id="@+id/editText9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"/>

        <EditText
            android:id="@+id/editText15"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"/>

        <EditText
            android:id="@+id/editText14"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"/>

        <EditText
            android:id="@+id/editText10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"/>

        <EditText
            android:id="@+id/editText12"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"/>

        <EditText
            android:id="@+id/editText13"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"/>

        <EditText
            android:id="@+id/editText11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="Name"/>

        <Button
            android:id="@+id/btn_signup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SignUp"/>
    </LinearLayout>
</ScrollView>

Code in AndroidMaifest.xml for the activity

    <activity
        android:name=".ScrollView"
        android:label="@string/title_activity_scroll_view"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>
  • My point is placement of SignUp button at the bottom which is tricky part and in above code there is no SignUp button. – Safeer Jul 03 '17 at 17:14
  • Look carefully I have add a button that can be SignUp or anything else. –  Jul 04 '17 at 04:21
  • This snippet doesn't place the SignUp button at the bottom. Just try your snippet in Nexus7 – Safeer Jul 04 '17 at 06:27
  • I have use 15 EditText and 1 Button at the bottom .... "Just try your snippet in Nexus7" What it means. –  Jul 04 '17 at 12:04
  • Is your problem related with Nexus7 –  Jul 04 '17 at 12:05
  • Can you share your layout code? and AndroidMaifest.xml code for your activity? –  Jul 04 '17 at 12:06
0

Wrap your layout in a scroll view, since scroll view can have only one child, it would be best for you to wrap your Relative layout in it.

<ScrollView>
 <RelativeLayout>
  ...
 </RelativeLayout>
</ScrollView>
Kshitij Saxena
  • 930
  • 8
  • 19