misterios
misterios

Reputation: 354

How make layout scrollable when softKeyBoard hides buttons and other elements [ANDROID]

my goal is to make login ui with footer text, also page should be scrollable whenever content wont show on a view.

I add scroll view in my layout but, when keyboard appears scroll doesn't works anyn suggestions ? those doesn't work, I don't want that button appears above the keyboard

android:windowSoftInputMode="stateHidden|adjustPan" android:windowSoftInputMode="stateHidden|adjustResize"

<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".auth.AuthFragment">
    
            <androidx.core.widget.NestedScrollView
                android:id="@+id/scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_constraintBottom_toTopOf="@id/footer">
    
                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/authConstraint"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
    
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/usernameInputLayout"
                        android:layout_width="384dp"
                        android:layout_height="75dp">
    
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/usernameInputEditText"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"/>
    
                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/uSubmit"
                        android:layout_width="match_parent"
                       app:layout_constraintTop_toBottomOf="@+id/usernameInputLayout" />
    
                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/uRegistration"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:backgroundTint="#2C2C2E"
                        android:text="SIGNIN"
                        android:textSize="30sp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="@+id/uSubmit"
                        app:layout_constraintStart_toStartOf="@+id/uSubmit"
                        app:layout_constraintTop_toBottomOf="@+id/uSubmit" />
                </androidx.constraintlayout.widget.ConstraintLayout>
            </androidx.core.widget.NestedScrollView>
    
            <FrameLayout
                android:id="@+id/footer"
                android:layout_width="match_parent"
                android:layout_height="70dp"
                android:background="@color/black"
                app:layout_constraintBottom_toBottomOf="@+id/scroll"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent">
    
                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <TextView
                        android:layout_width="358dp"
                        android:layout_height="wrap_content"
                </androidx.constraintlayout.widget.ConstraintLayout>
            </FrameLayout>
    
        </androidx.constraintlayout.widget.ConstraintLayout>
    </layout>

Upvotes: 0

Views: 37

Answers (1)

Dmytro Batyuk
Dmytro Batyuk

Reputation: 974

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true">

           <androidx.constraintlayout.widget.ConstraintLayout
               android:layout_width="match_parent"
               android:layout_height="match_parent">

              <View
                 android:id="@id/view_1"
                 ...
                 app:layout_constraintTop_toTopOf="parent" />

              <View
                 android:id="@id/view_2"
                 ...
                 app:layout_constraintTop_toBottomOf="@id/view_1" />

              <View
                 android:id="@id/view_3"
                 ...
                 app:layout_constraintTop_toBottomOf="@id/view_2" />

              <View
                 android:id="@id/view_4"
                 ...
                 app:layout_constraintTop_toBottomOf="@id/view_3"
                 app:layout_constraintBottom_toBottomOf="parent" />

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

Make sure you have constraints between all views, parent top and parent bottom. From my example you can see constraints PARENT_TOP <- View 1 <- View 2 <- View 3 <- View 4 -> PARENT_BOTTOM

Upvotes: 1

Related Questions