ScrollView error even though it has one child

  android, android-layout

I’m trying to add a ScrollView to my layout as the root view but I’m getting a "ScrollView can host only one direct child" error. I don’t understand why I’m getting this error because my layout does have one child. Can someone show me what I’m doing wrong here? I’ve tried everything but nothing seems to work. Here’s my layout.

    <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="@drawable/ic_back_back"
     tools:context=".login.LoginFragment">

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

    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="32dp"
        android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/contentLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="24dp">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="32dp"
                android:labelFor="@id/editTextTextPersonName6"
                android:text="@string/username"
                android:textSize="24sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/imageView5" />

            <TextView
                android:id="@+id/editTextTextPersonClientPassword"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:labelFor="@id/editTextTextPersonName6"
                android:text="@string/password"
                android:textSize="24sp"
                app:layout_constraintEnd_toEndOf="@+id/editTextTextPersonClientName"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="@+id/editTextTextPersonClientName"
                app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonClientName" />

            <EditText
                android:id="@+id/editTextTextPersonClientName"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:autofillHints=""
                android:background="@drawable/round_button"
                android:ems="10"
                android:hint="@string/type_username"
                android:imeOptions="actionNext"
                android:inputType="textPersonName"
                android:padding="6sp"
                android:textSize="18sp"
                app:layout_constraintEnd_toEndOf="@+id/textView3"
                app:layout_constraintStart_toStartOf="@+id/textView3"
                app:layout_constraintTop_toBottomOf="@+id/textView3" />

            <EditText
                android:id="@+id/editTextTextPersonName6"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:autofillHints=""
                android:background="@drawable/round_button"
                android:ems="10"
                android:hint="@string/type_password"
                android:imeOptions="actionDone"
                android:inputType="textPassword"
                android:padding="6sp"
                android:textSize="18sp"
                app:layout_constraintEnd_toEndOf="@+id/editTextTextPersonClientPassword"
                app:layout_constraintStart_toStartOf="@+id/editTextTextPersonClientPassword"
                app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonClientPassword" />

            <Button
                android:id="@+id/buttonLoginButtonFragmentActivity"
                android:layout_width="0dp"
                android:layout_height="59dp"
                android:layout_marginTop="32dp"
                android:text="@string/login"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@+id/editTextTextPersonName6"
                app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName6"
                app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName6" />

            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="TODO"
                android:src="@drawable/ic_sisi_logo"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

Source: Android Questions

LEAVE A COMMENT