Search code examples
androidxmlscrollviewandroid-alertdialogandroidx

Scrollview not working in layout injected into AlertDialog


I am injecting a layout into an AlertDialog.

In this layout, I have a group of views and below this group, I have a TextView.

I need this last TextView to be still. But the group of previous views should be scrollable. So I added a ScrollView before the first view and right before the TextView (because I don't want to include it).

Also, in my group of views, I have two views "gone" and they are only visible when I click on a button (which is working perfectly).

But my scrollview barely moves never lets me see the whole group of view when needed.

Could anyone let me know what I am doing wrong please?

EDIT: I tried using this post Issue when using Scrollview inside Dialog but even if my scrollview is working, I don't see my last TextView (the one outside the scrollview) anymore.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activityCameraParentCL"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <ScrollView
        android:id="@+id/activityCameraParametersSV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/activityCameraMainLL"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true">

            <LinearLayout
                android:id="@+id/activityCameraSerialNumberLL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingBottom="10dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@id/activityCameraMainLL">

                <TextView
                    android:id="@+id/activityCameraSerialNumberTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/activityCameraParametersSerialNumber"
                    android:textStyle="bold" />

                <EditText
                    android:id="@+id/activityCameraSerialNumberET"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="5" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/activityCameraModelNameLL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingBottom="10dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/activityCameraSerialNumberLL">

                <TextView
                    android:id="@+id/activityCameraModelNameTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/activityCameraParametersModelName"
                    android:textStyle="bold" />

                <EditText
                    android:id="@+id/activityCameraModelNameET"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="5" />
            </LinearLayout>

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/activityCameraMarkerLL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingBottom="10dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/activityCameraModelNameLL">

                <TextView
                    android:id="@+id/activityCameraMarkerTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="@string/activityCameraParametersMarker"
                    android:textStyle="bold"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <ImageButton
                    android:id="@+id/activityCameraMarkerInfoIB"
                    android:layout_width="20dp"
                    android:layout_height="30dp"
                    android:layout_marginTop="5dp"
                    android:backgroundTint="@color/black"
                    android:src="@drawable/ic_action_info"
                    app:layout_constraintStart_toEndOf="@id/activityCameraMarkerTV"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/activityCameraMarkerYesButton"
                    android:layout_width="80dp"
                    android:layout_height="40dp"
                    android:gravity="center"
                    android:text="@string/yes"
                    android:textColor="@color/white"
                    app:layout_constraintEnd_toStartOf="@+id/activityCameraMarkerNoButton"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/activityCameraMarkerNoButton"
                    android:layout_width="80dp"
                    android:layout_height="40dp"
                    android:layout_marginEnd="10dp"
                    android:gravity="center"
                    android:text="@string/no"
                    android:textColor="@color/white"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/activityCameraMarkerInfoTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="@string/activityCameraParametersMarkerInfo"
                    android:visibility="gone"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/activityCameraMarkerTV" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <TextView
                android:id="@+id/activityCamera15CreditTV"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:text="@string/activityCameraParameters15Credits"
                android:textAlignment="center"
                android:textColor="@android:color/holo_red_dark"
                android:textSize="12sp"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/activityCameraMarkerLL" />

            <EditText
                android:id="@+id/activityCameraParametersDescriptionET"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:hint="@string/edittext_hint"
                android:inputType="textMultiLine"
                android:minLines="2"
                android:overScrollMode="always"
                android:paddingBottom="10dp"
                android:scrollbarStyle="insideInset"
                android:scrollbars="vertical"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/activityCamera15CreditTV" />

            <LinearLayout
                android:id="@+id/activityCameraSpecimenLanguageLL"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:orientation="horizontal"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/activityCameraParametersDescriptionET">

                <TextView
                    android:id="@+id/activityCameraSpecimenLanguageTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/activityCameraParametersSpecimenLanguage"
                    android:textStyle="bold" />

                <Spinner
                    android:id="@+id/activityCameraSpecimenLanguageSpinner"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" />

            </LinearLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

    <TextView
        android:id="@+id/activityCameraValidationTV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="@string/validationBeforePursue"
        android:textAlignment="center"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/activityCameraParametersSV" />


</androidx.constraintlayout.widget.ConstraintLayout>

Solution

  • Try using NestedScrollView instead of the regular ScrollView ?