1

I am not sure what I am doing wrong. I have read most of the samples I could find on YouTube and other places and tried the solutions they gave, but have not been able to resolve my issue.

The issue is that I am using ConstraintLayout inside ScrollView. I try to scroll, it does not really scroll at all. Therefore, some elements at the bottom are not shown. Below is my code. What am I doing wrong?

The below code is edited to include the corrections given and it is still not working. I really appreciate you suggestions and your intentions to help.

   <?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:id="@+id/scrolvw"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:fitsSystemWindows="false"
    android:scrollbars="vertical"



    android:orientation="vertical">

    <androidx.constraintlayout.widget.ConstraintLayout

        android:id="@+id/constLay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context=".RegisterActivity">


        <ImageView
            android:id="@+id/regAppLogo"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:contentDescription="@string/fambuk_logo"
            app:layout_constraintBottom_toTopOf="@+id/firstNameInputLayout"
            app:layout_constraintDimensionRatio="3:0.45"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@mipmap/fambuklogo"
            tools:ignore="ImageContrastCheck" />

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/firstNameInputLayout"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="280dp"

            android:layout_height="48dp"
            android:layout_marginStart="1dp"
            android:layout_marginLeft="1dp"
            android:layout_marginEnd="1dp"
            android:layout_marginRight="1dp"
            android:hint="First name"

            app:layout_constraintBottom_toTopOf="@+id/lastnameInputLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/regAppLogo">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/firstNameEditText"
                style="@style/Widget.Design.TextInputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:height="48dp"

                app:layout_constraintDimensionRatio="5:1"
                tools:ignore="TextContrastCheck" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/lastnameInputLayout"
            style="@style/Theme.AppCompat.Light.NoActionBar"
            android:layout_width="280dp"
            android:layout_height="48dp"
            android:layout_marginTop="14dp"
            android:hint="Last name"
            app:layout_constraintBottom_toTopOf="@+id/userNameInputLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/firstNameInputLayout">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/lastNameEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:ignore="TextContrastCheck" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/userNameInputLayout"
            style="@style/Theme.AppCompat.Light.NoActionBar"
            android:layout_width="280dp"
            android:layout_height="48dp"
            android:layout_marginStart="1dp"
            android:layout_marginLeft="1dp"
            android:layout_marginTop="14dp"
            android:layout_marginEnd="1dp"
            android:layout_marginRight="1dp"
            android:hint="Username"
            app:layout_constraintBottom_toTopOf="@+id/emailLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/lastnameInputLayout">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/userNameEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:ignore="TextContrastCheck" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/emailLayout"
            android:layout_width="280dp"
            android:layout_height="48dp"
            android:layout_marginStart="1dp"
            android:layout_marginLeft="1dp"
            android:layout_marginTop="14dp"
            android:layout_marginEnd="1dp"
            android:layout_marginRight="1dp"
            android:hint="Email"
            app:layout_constraintBottom_toTopOf="@+id/passInputLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/userNameInputLayout">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/emailEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                tools:ignore="TextContrastCheck" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/passInputLayout"
            android:layout_width="280dp"
            android:layout_height="48dp"
            android:layout_marginStart="1dp"
            android:layout_marginLeft="1dp"
            android:layout_marginTop="14dp"
            android:layout_marginEnd="1dp"
            android:layout_marginRight="1dp"
            android:hint="Password"
            app:layout_constraintBottom_toTopOf="@+id/button"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/emailLayout">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/passEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="36dp"

                app:layout_constraintBottom_toTopOf="@+id/button"
                app:layout_constraintTop_toBottomOf="@+id/passInputLayout"
                tools:ignore="TextContrastCheck"
                tools:layout_editor_absoluteX="-2dp" />

        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="48dp"
            android:layout_marginTop="14dp"
            android:text="Sign up"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/passInputLayout"
            tools:ignore="TextContrastCheck" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="Already have an account ?"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button"
            tools:ignore="TextContrastCheck" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="Sign in"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.473"
            app:layout_constraintStart_toEndOf="@+id/textView2"
            app:layout_constraintTop_toBottomOf="@+id/button"
            tools:ignore="TextContrastCheck" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="20dp" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="255dp"
            android:layout_height="23dp"
            android:layout_marginTop="8dp"

            android:orientation="horizontal"
            android:text="By signing up you agree with our terms and conditions"
            android:visibility="visible"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView2"
            tools:ignore="TextContrastCheck" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Screenshot of what shows up from the code

Gab
  • 11
  • 2
  • Can you try adding the following to the `ScrollView`: `android:fitsSystemWindows="false"` `android:scrollbars="vertical"` and let me know if it works? – Wrichik Basu Sep 05 '22 at 07:27
  • 1
    Your new layout works OK in my emulator. Is something else happening with the layout? Without further information, I don't think anyone will be able to assist you. Posting a sample project that exhibits the problem may help. – Cheticamp Sep 06 '22 at 21:46
  • I used 2.7 QVGA emulator to get the small screen size phone effect. Which emulator did you use ? Are there emulators that have compatibility problem with scrollview or scrolling effects? I am very new in using android studio or into developing android app, so pardon some of my questions if they sound basic ? – Gab Sep 07 '22 at 04:09
  • I was using a Nexus 5 emulator but I tried you 2.7 QVGA emulator and I still get a full scroll. Something else is going on that is not evident from your question. Can you post what you are seeing? Maybe that will give a clue. – Cheticamp Sep 07 '22 at 04:45
  • Thanks for this. I think it is good to know that you are not experiencing any problem from your side. I have just uploaded a screenshot of my android studio working environment. let me know if it helps or not and we see what next to do. – Gab Sep 07 '22 at 08:45
  • Could it be a code missing in the themes, gradle or manifest ? Some code I may need to add that I have not done ? – Gab Sep 07 '22 at 08:52
  • You layout now has all constraints defined. I can't reproduce the scrolling issue, so I have nothing further to add. – Cheticamp Sep 07 '22 at 13:43
  • I've tried the above XML on the same emulator that you are using with `API 28`. I recommend you start a new project and only add the above and see if it works or not. If it does work then, you have to compare or complete working on the new project! – Mohamad Ghaith Alzin Sep 09 '22 at 00:44

1 Answers1

0

The TextViews "textView2", "textView3" and "textView4" do not have vertical constraints. They probably look OK in the Android Studio designer because they have tools:layout_editor_absoluteY="420dp" set. That setting only has value in the designer and has no effect when the app is run. Without a vertical contraint, the view will shift to the top.

Make sure all of your view have horizontal and vertical constraints set.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • Thanks for your answer. All the TextViews had both vertical and horizontal constraints. I removed it to try some other solutions while I sent the initial post here. I forgot to add it before sending the post. But I already did that and it did not work. – Gab Sep 05 '22 at 22:05
  • Post the XML that is not working with the constraints set. – Cheticamp Sep 06 '22 at 00:24
  • Still not working after I added the constraints in the Textviews and also included android:fitsSystemWindows="false". Above is the edited code. – Gab Sep 06 '22 at 21:36