-1

I am new to designing layouts , and i am trying to make this layout resizable with android:windowSoftInputMode="adjustResize"

everything is working perfectly but the problem is i can't get the last relative layout to go all the way to the bottom i tried to set gravity to bottom but it did not work

i added a line in my code where my problem occurs

here is my activity layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="#000000"
    tools:context=".testLayout">

    <RelativeLayout
        android:id="@+id/mainLayout"
        android:layout_width="match_parent"
        android:gravity="center"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/logoLayout"
            >


            <ImageView
                android:layout_width="140dp"
                android:layout_height="35dp"
                android:layout_marginTop="10dp"
                android:layout_marginStart="10dp"
                android:background="@drawable/nlogo">


            </ImageView>


        </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/logoLayout1"
                android:layout_below="@id/logoLayout"

                >

                <EditText
                    android:id="@+id/testUsernameText"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_marginStart="50dp"
                    android:layout_marginTop="48dp"
                    android:layout_marginEnd="50dp"
                    android:background="@drawable/rounded_background"
                    android:gravity="center_vertical"
                    android:hint="Username"
                    android:paddingStart="10dp"
                    android:text=""
                    android:textColor="@color/white"
                    android:textColorHint="@color/hint_color"
                    android:textCursorDrawable="@null"
                    android:textSize="18sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/imageView2" />

                <EditText
                    android:id="@+id/testPasswordText"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_marginStart="50dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginEnd="50dp"
                    android:background="@drawable/rounded_background"
                    android:gravity="center_vertical"
                    android:hint="Password"
                    android:paddingStart="10dp"
                    android:text=""
                    android:textColor="@color/white"
                    android:textColorHint="@color/hint_color"
                    android:textCursorDrawable="@null"
                    android:textSize="18sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/imageView2" />

                <EditText
                    android:id="@+id/testEmailText"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_marginStart="50dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginEnd="50dp"
                    android:background="@drawable/rounded_background"
                    android:gravity="center_vertical"
                    android:hint="Email"
                    android:paddingStart="10dp"
                    android:text=""
                    android:textColor="@color/white"
                    android:textColorHint="@color/hint_color"
                    android:textCursorDrawable="@null"
                    android:textSize="18sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/imageView2" />

                <EditText
                    android:id="@+id/testFullNameText"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_marginStart="50dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginEnd="50dp"
                    android:background="@drawable/rounded_background"
                    android:gravity="center_vertical"
                    android:hint="Full Name"
                    android:paddingStart="10dp"
                    android:text=""
                    android:textColor="@color/white"
                    android:textColorHint="@color/hint_color"
                    android:textCursorDrawable="@null"
                    android:textSize="18sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/imageView2" />

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="50dp"
                    android:layout_marginStart="50dp"
                    android:layout_marginEnd="50dp"
                    android:text="Sign Up"
                    android:background="@drawable/rounded_button"
                    />


            </LinearLayout>

<!-- here is the problem -->


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/logoLayout1"
    android:id="@+id/footerLayout"
    android:layout_alignParentBottom="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentBottom="true">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="false"
                android:text="Welcome to ....."
                android:textSize="15sp" />



    </LinearLayout>




</RelativeLayout>




    </RelativeLayout>

many thanks in advance

nick isra
  • 99
  • 1
  • 9
  • Your first viewgroup needs to have wrap_content, as you has already done, in order for the scrollview to scroll... but i think android:layout_alignParentBottom="true" is not possible since the relativelayout has height="wrap_content"... consider using constraintlayout instead? – Mathias Kirkegaard Oct 02 '19 at 08:44
  • i tried constraintLayout but adjustResize does not resize everything with constraintLayout. what i am trying to achieve is that https://stackoverflow.com/questions/16411056/how-to-adjust-layout-when-soft-keyboard-appears – nick isra Oct 02 '19 at 08:47
  • Have you tryied setting: android:fillViewport="true" on your scrollivew? – Mathias Kirkegaard Oct 02 '19 at 08:55

2 Answers2

0

I have tried your layout in my temporary activity and adding android:fillViewport="true" in the ScrollView worked for me.

Vikas
  • 136
  • 6
0

Here is the solution:

Add this line in Manifest file for your activity

android:windowSoftInputMode="adjustResize"

I have bit modified the XML file code to make it very easy to read and less view hierarchy.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:fillViewport="true">

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

        <ImageView
            android:layout_width="140dp"
            android:layout_height="35dp"
            android:layout_marginStart="10dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/ic_eye"
            android:contentDescription="@null" />

        <EditText
            android:id="@+id/testUsernameText"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginStart="50dp"
            android:layout_marginTop="48dp"
            android:layout_marginEnd="50dp"
            android:gravity="center_vertical"
            android:hint="Username"
            android:paddingStart="10dp"
            android:text=""
            android:textColor="@color/colorTextWhite"
            android:textColorHint="@color/colorTextBlue"
            android:textCursorDrawable="@null"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/testPasswordText"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginStart="50dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="50dp"
            android:gravity="center_vertical"
            android:hint="Password"
            android:paddingStart="10dp"
            android:text=""
            android:textColor="@color/colorTextWhite"
            android:textColorHint="@color/colorTextBlue"
            android:textCursorDrawable="@null"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/testEmailText"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginStart="50dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="50dp"
            android:gravity="center_vertical"
            android:hint="Email"
            android:paddingStart="10dp"
            android:text=""
            android:textColor="@color/colorTextWhite"
            android:textColorHint="@color/colorTextBlue"
            android:textCursorDrawable="@null"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/testFullNameText"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginStart="50dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="50dp"
            android:gravity="center_vertical"
            android:hint="Full Name"
            android:paddingStart="10dp"
            android:text=""
            android:textColor="@color/colorTextWhite"
            android:textColorHint="@color/colorTextBlue"
            android:textCursorDrawable="@null"
            android:textSize="18sp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="50dp"
            android:layout_marginTop="50dp"
            android:layout_marginEnd="50dp"
            android:background="@drawable/shape_calendar_bg"
            android:text="Sign Up" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="bottom"
            android:text="Welcome to ....."
            android:textColor="@color/colorTextWhite"
            android:textSize="15sp" />

    </LinearLayout>

</ScrollView>

While the keyboard is open

While keyboard is open

Jaymin
  • 2,879
  • 3
  • 19
  • 35
  • thanks i need to add android:fillViewport="true" to my scroll view, but i was wondering what is the difference between my code and yours? linear layout won't be the same for all screen sizes? and does android:windowSoftInputMode="adjustResize" work with constraintLayout? – nick isra Oct 02 '19 at 09:34
  • Yes, it will work and in my code is optimized and have less number of view hierarchy. I also have added `android:fillViewport="true"`. – Jaymin Oct 02 '19 at 09:39
  • I tried yours and mine, but only the "Welcome to..." got higher , i tried lowering the ("username","password"..) boxes so it would be hidden when keyboard pop up , but when i did that, the resizing doesn't work and it stays the same , on both your code and mine – nick isra Oct 02 '19 at 11:29