1

I need to use a <scrollview> layout that consists of some EditTexts and a linear of Buttons at the bottom, but the problem is when the soft keyboard is out, the layout doesn't scroll and it hides the Buttons' linear completely and the main linear (@+id/main) goes out of the screen!

Here's a recap of my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  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="#03A9F4"
  android:gravity="center"
  >

  <RelativeLayout
    android:id="@+id/main"
    android:layout_width="310dip"
    android:layout_height="485dip"
    android:background="#03A9F4"
    android:gravity="center">

    <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="435dip"
      android:layout_alignParentBottom="true"
      android:layout_alignParentTop="false"
      android:background="@drawable/border_signup_signin_auth">

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

        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="70dip"
          android:orientation="vertical"
          tools:ignore="UselessLeaf">
        </LinearLayout>


        <ScrollView
          android:id="@+id/ScrollMain"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:isScrollContainer="false"
          >

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

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="80dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="10dip"
              android:paddingRight="10dip">

              <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical"
                android:paddingEnd="5dip"
                tools:ignore="RtlSymmetry">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>

              <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>
            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="80dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="10dip"
              android:paddingRight="10dip">

              <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical"
                android:paddingEnd="5dip"
                tools:ignore="RtlSymmetry">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  />
              </LinearLayout>

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

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>
            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="70dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="10dip"
              android:paddingRight="10dip">

              <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical"
                android:paddingEnd="5dip"
                tools:ignore="RtlSymmetry">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>

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

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  />
              </LinearLayout>
            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="70dip"
              android:orientation="vertical"
              android:paddingEnd="10dip"
              tools:ignore="RtlSymmetry">

              <com.rengwuxian.materialedittext.MaterialEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />

            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="60dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="5dip"
              android:paddingRight="5dip">

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

                <Button
                  android:id="@+id/btnSignUp"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:text="test"
                  android:textSize="16sp"/>
              </LinearLayout>

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

                <Button
                  android:id="@+id/btnGuest"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:text="test"
                  android:textSize="16sp"
                  />
              </LinearLayout>
            </LinearLayout>
          </LinearLayout>
        </ScrollView>

      </LinearLayout>
    </RelativeLayout>

    <ImageView
      android:id="@+id/imageView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerInParent="false"
      android:contentDescription="TODO"
      app:srcCompat="@mipmap/signup"
      tools:ignore="ContentDescription"/>

  </RelativeLayout>
</LinearLayout>

And in the manifest I have tried the attribute:

android:windowSoftInputMode="adjustResize"

Also, I have tried same questions' solutions like:

But didn't work for me.

Does anyone know why it doesn't work?
Thanks in advance!

Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
Emad
  • 588
  • 1
  • 9
  • 22

3 Answers3

3

Try this :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/profile_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:windowSoftInputMode="adjustResize|adjustPan"
    tools:context="com.example.user22.hotelxp.Activity.MyProfileActivity">


   <ImageView
       android:id="@+id/imageView"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
       android:layout_centerInParent="false"
       android:contentDescription="TODO"
       app:srcCompat="@mipmap/signup"
       android:layout_alignParentBottom="true"
       tools:ignore="ContentDescription"/>

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

        <ScrollView
            android:id="@+id/layout_scroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="80dip"
                    android:baselineAligned="false"
                    android:orientation="horizontal"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip">

                    <LinearLayout
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:orientation="vertical"
                        android:paddingEnd="5dip"
                        tools:ignore="RtlSymmetry">

                        <com.rengwuxian.materialedittext.MaterialEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"/>
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:orientation="vertical">

                        <com.rengwuxian.materialedittext.MaterialEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"/>
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="80dip"
                    android:baselineAligned="false"
                    android:orientation="horizontal"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:orientation="vertical"
                        android:paddingEnd="5dip"
                        tools:ignore="RtlSymmetry">

                        <com.rengwuxian.materialedittext.MaterialEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            />
                    </LinearLayout>

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

                        <com.rengwuxian.materialedittext.MaterialEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"/>
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="70dip"
                    android:baselineAligned="false"
                    android:orientation="horizontal"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:orientation="vertical"
                        android:paddingEnd="5dip"
                        tools:ignore="RtlSymmetry">

                        <com.rengwuxian.materialedittext.MaterialEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"/>
                    </LinearLayout>

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

                        <com.rengwuxian.materialedittext.MaterialEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="70dip"
                    android:orientation="vertical"
                    android:paddingEnd="10dip"
                    tools:ignore="RtlSymmetry">

                    <com.rengwuxian.materialedittext.MaterialEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        />

                </LinearLayout>


            </LinearLayout>


        </ScrollView>


    </LinearLayout>


    <RelativeLayout
        android:id="@+id/btn_layout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="60dip"
            android:baselineAligned="false"
            android:orientation="horizontal"
            android:paddingLeft="5dip"
            android:paddingRight="5dip">

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

                <Button
                    android:id="@+id/btnSignUp"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="test"
                    android:textSize="16sp"/>
            </LinearLayout>

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

                <Button
                    android:id="@+id/btnGuest"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="test"
                    android:textSize="16sp"
                    />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>

In AndroidManifest :

android:windowSoftInputMode="stateHidden|adjustResize" 
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
2

Add android:windowSoftInputMode="adjustPan|adjustResize" to android manifest where your Activity is called

or

add this line on onCreate() method

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
Ritu Suman Mohanty
  • 734
  • 1
  • 6
  • 15
1

Finally, I found the solution.
I just changed the Scrollview's parent to RelativeLayout (instead of LinearLayout).
I don't know why, but it fixed the issue. Maybe in layouts that its main Layout is RelativeLayout, Scrollview's parent should be a RelativeLayout! (But I'm not sure)

Here is fixed code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  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="#03A9F4"
  android:gravity="center"
  >

  <RelativeLayout
    android:id="@+id/main"
    android:layout_width="310dip"
    android:layout_height="485dip"
    android:background="#03A9F4"
    android:gravity="center">

    <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="435dip"
      android:layout_alignParentBottom="true"
      android:layout_alignParentTop="false"
      android:background="@drawable/border_signup_signin_auth">

      <!--It changed to RelativeLayout and fix the problem-->
      <RelativeLayout  
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="70dip"
          android:orientation="vertical"
          tools:ignore="UselessLeaf">
        </LinearLayout>


        <ScrollView
          android:id="@+id/ScrollMain"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:isScrollContainer="false"
          >

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

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="80dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="10dip"
              android:paddingRight="10dip">

              <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical"
                android:paddingEnd="5dip"
                tools:ignore="RtlSymmetry">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>

              <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>
            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="80dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="10dip"
              android:paddingRight="10dip">

              <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical"
                android:paddingEnd="5dip"
                tools:ignore="RtlSymmetry">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  />
              </LinearLayout>

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

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>
            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="70dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="10dip"
              android:paddingRight="10dip">

              <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:orientation="vertical"
                android:paddingEnd="5dip"
                tools:ignore="RtlSymmetry">

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>
              </LinearLayout>

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

                <com.rengwuxian.materialedittext.MaterialEditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  />
              </LinearLayout>
            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="70dip"
              android:orientation="vertical"
              android:paddingEnd="10dip"
              tools:ignore="RtlSymmetry">

              <com.rengwuxian.materialedittext.MaterialEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />

            </LinearLayout>

            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="60dip"
              android:baselineAligned="false"
              android:orientation="horizontal"
              android:paddingLeft="5dip"
              android:paddingRight="5dip">

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

                <Button
                  android:id="@+id/btnSignUp"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:text="test"
                  android:textSize="16sp"/>
              </LinearLayout>

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

                <Button
                  android:id="@+id/btnGuest"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:text="test"
                  android:textSize="16sp"
                  />
              </LinearLayout>
            </LinearLayout>
          </LinearLayout>
        </ScrollView>

      </LinearLayout>
    </RelativeLayout>

    <ImageView
      android:id="@+id/imageView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerInParent="false"
      android:contentDescription="TODO"
      app:srcCompat="@mipmap/signup"
      tools:ignore="ContentDescription"/>

  </RelativeLayout>
</LinearLayout>

And it wasn't necessary to add anything to Java's file or Manifest.

output

Emad
  • 588
  • 1
  • 9
  • 22