0

I'm trying to resize my layout to fit the screen when the keyboard appears, I followed the instructions provided here: How to adjust layout when soft keyboard appears

But still does not seem to work, the only text that goes higher is "Welcome to ....", and if you lower my boxes (username, password, e-mail, full name) so that they would be hidden when the keyboard shows up so nothing happens even "welcome to ..." moves up.

I don't know what the problem might be 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:fillViewport="true"
    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>



<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>

and here is my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".testLayout"
            android:windowSoftInputMode="adjustResize">
        </activity>
        <activity android:name=".registerActivity" />
        <activity android:name=".loginActivity" />
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest>

Also does adjustResize work with constraintLayout as well!

Thanks in advance.

G. Ciardini
  • 1,210
  • 1
  • 17
  • 32
nick isra
  • 99
  • 1
  • 9

1 Answers1

0

Try this will resize your screen

Add android:fitsSystemWindows="true" to scrollview

<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:fillViewport="true"
android:layout_height="match_parent"
android:background="#000000"
android:fitsSystemWindows="true"
tools:context=".testLayout">

and add android:layout_gravity="center" in RelativeLayout

 <RelativeLayout
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_gravity="center"
    android:layout_height="wrap_content">
Ankit
  • 1,068
  • 6
  • 10
  • layout_gravity="center" is already in the RelativeLayout under id mainLayout and also i tried adding fitsSystemWindows="true" but still it's not resizing anything – nick isra Oct 02 '19 at 13:33
  • android:gravity="center" is there in your code not android:layout_gravity="center" – Ankit Oct 02 '19 at 13:35
  • ah sorry that was my bad, i added that now its moving , but also the logo top is moving and the bottom text is still hidden and "Full Name" box as well, its not working as they described it , like in facebook layout. – nick isra Oct 02 '19 at 14:07