0

I have made a sign in a layout that looks as follows:

enter image description here

The xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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/colorWhite"
    android:fillViewport="true"
    tools:context=".SignInActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintHeight_percent="1">

    <ImageView
        android:id="@+id/image_signin"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:layout_marginEnd="8dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@drawable/img_signin"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.2"
        app:layout_constraintHorizontal_bias="0.55"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.48"/>

    <TextView
        android:id="@+id/text_sign_in"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="40dp"
        android:layout_marginTop="60dp"
        android:fontFamily="@font/assistant_semibold"
        android:text="Sign In"
        android:textColor="@color/colorLightPurple"
        android:textSize="24dp"
        app:layout_constraintHeight_percent="0.05"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/image_signin"
        app:layout_constraintWidth_percent="0.3" />

    <EditText
        android:id="@+id/et_sign_in_email"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:layout_marginTop="36dp"
        android:drawablePadding="10dp"
        android:textColor="@color/colorBlackText"
        android:background="@drawable/btn_underline"
        android:drawableStart="@drawable/ic_mail_outline_black_24dp"
        android:drawableLeft="@drawable/ic_mail_outline_black_24dp"
        android:fontFamily="@font/assistant_semibold"
        android:hint="E-mail"
        app:layout_constraintHeight_percent="0.06"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/text_sign_in"/>

    <EditText
        android:id="@+id/et_sign_in_password"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:layout_marginTop="20dp"
        android:drawablePadding="10dp"
        android:textColor="@color/colorBlackText"
        android:background="@drawable/btn_underline"
        android:drawableStart="@drawable/ic_lock_outline_black_24dp"
        android:drawableLeft="@drawable/ic_lock_outline_black_24dp"
        android:fontFamily="@font/assistant_semibold"
        android:hint="Password"
        android:inputType="textPassword"
        app:layout_constraintHeight_percent="0.06"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/et_sign_in_email"/>

    <Button
        android:id="@+id/button_sign_in"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="40dp"
        android:layout_marginEnd="40dp"
        android:layout_marginTop="40dp"
        app:layout_constraintHeight_percent="0.08"
        app:layout_constraintTop_toBottomOf="@+id/et_sign_in_password"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:background="@drawable/btn_rounded_purple"
        android:fontFamily="@font/assistant"
        android:text="Sign In"
        android:textAllCaps="false"
        android:textColor="@color/colorWhite"
        android:textSize="20dp"/>

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

When I type the email/password the keyboard hides the sign-in button so I added to my manifest android:windowSoftInputMode="adjustResize".

The result is as follows:

enter image description here

Is there a way to make the objects inside my layout to remain the same size always and just to push the whole layout above the keyboard?

I specifically made the whole layout inside ScrollView so it will be able to move but the problem is that the keyboard is not "part of the screen" it's more like a float from my understanding so it does not move the layout.

Thank you

Ben
  • 1,737
  • 2
  • 30
  • 61

1 Answers1

0

You can use a ConstraintLayout:

    <androidx.constraintlayout.widget.ConstraintLayout
     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:id="@+id/constraint_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true">

        <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:src="@drawable/image"
        app:layout_constraintBottom_toTopOf="@+id/username"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

        <EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
        ...
    </androidx.constraintlayout.widget.ConstraintLayout>
mirohero
  • 3
  • 4
  • This is what I used and I inserted it all inside scrollview to have the option to move the view once the keyboard is shown. – Ben Sep 30 '19 at 20:09
  • to confirm exactly what ben said, we literally just did this on our login screen about an hour ago because of a similar issue. – John Lord Sep 30 '19 at 20:16
  • @JohnLord well, hopefully, we both will get an answer here =] – Ben Sep 30 '19 at 20:25
  • actually we had issues nesting the constraint inside a relative layout. Your mileage may vary. – John Lord Oct 01 '19 at 18:19