Pestilence01
Pestilence01

Reputation: 35

Android Studio Kotlin how to make a Constraint Layout scrollable with Scroll View?

Basically I want to make the screen scrollable when the keyboard appears during text input, but no matter what I do it refuses to work. I made a Scroll View and put a Constraint Layout with all the elements in it. But it just refuses to scroll when the keyboard pops up.

This is the .xml

<?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:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/dark_purple"
        tools:context=".LoginActivity">


        <ImageView
            android:id="@+id/IV_top_left_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/top_left_illustration_login_screen"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            />

        <ImageView
            android:id="@+id/IV_top_right_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/top_right_illustration_login_screen"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            />

        <ImageView
            android:id="@+id/IV_triangle_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="56dp"
            android:layout_marginTop="181dp"
            android:src="@drawable/triangle"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:text="Shows"
            android:textColor="@color/white"
            android:textSize="34sp"
            android:textStyle="bold"
            app:layout_constraintStart_toEndOf="@+id/IV_triangle_login"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="178dp"/>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/TIL_password_login"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="130dp"
            android:layout_marginEnd="23dp"
            android:layout_marginStart="23dp"
            app:passwordToggleEnabled="true"
            app:endIconMode="password_toggle"
            android:hint="Password"
            app:boxStrokeColor="@color/white"
            android:textColorHint="@color/white"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@id/button_login"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/ET_password_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                app:boxStrokeColor="@color/white"
                android:textColorHint="@color/white"
                android:textColor="@color/white"
                android:textSize="16dp"
                android:maxLength="25"
                />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/TIL_email_login"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="12dp"
            android:layout_marginEnd="23dp"
            android:layout_marginStart="23dp"
            android:hint="Email"
            app:boxStrokeColor="@color/white"
            android:textColorHint="@color/white"
            android:backgroundTint="@color/white"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@id/TIL_password_login"
            >

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/ET_email_login"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:boxStrokeColor="@color/white"
                android:textColorHint="@color/white"
                android:textColor="@color/white"
                android:textSize="16dp"
                android:maxLength="35"
                />
        </com.google.android.material.textfield.TextInputLayout>

        <TextView
            android:id="@+id/ET_please_log_in"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="In order to continue please log in"
            android:textSize="17dp"
            android:textColor="@color/white"
            android:layout_marginBottom="23dp"
            android:layout_marginStart="23dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@id/TIL_email_login"
            />

        <TextView
            android:id="@+id/ET_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Login"
            android:textStyle="bold"
            android:textSize="36dp"
            android:textColor="@color/white"
            android:layout_marginBottom="16dp"
            android:layout_marginStart="23dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@id/ET_please_log_in"
            />

        <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/button_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            android:background="@drawable/rounded_button_login_toggled_on"
            android:enabled="false"
            android:layout_marginStart="24dp"
            android:layout_marginEnd="24dp"
            android:layout_marginBottom="32dp"
            android:textAllCaps="false"
            android:text="Login"
            android:textSize="17dp"
            android:textColor="@drawable/button_text_color_login"
            android:textStyle="bold"
            />

    </androidx.constraintlayout.widget.ConstraintLayout>


</ScrollView>

and this is how the activity looks like

enter image description here

I feel like the constraint to the button (bottom to bottom of parent) could be an issue. I enabled the fillViewport because without it it's broken. Any help would be appreciated.

Upvotes: 0

Views: 1002

Answers (1)

Pestilence01
Pestilence01

Reputation: 35

I fixed the issue by adding this attribute to the scroll view: app:layout_constraintBottom_toBottomOf="parent"

Upvotes: 1

Related Questions