3

I have ScrollView and few other views on top and bottom of it, it's inside ConstraintLayout. I tried many ways, No luck, Scrollview is taking full space instead of to provide scrolling and if provide a constraint to bottom view, then that view is not visible.

XML File:

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <!-- @style/Dialog.Title contains margins and font settings -->
        <TextView
            android:id="@+id/title_text_view"
            style="@style/Dialog.Title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="0dp"
            android:gravity="center_vertical"
            android:text="@string/device_settings_quality_dialog_title"
            app:layout_constraintBottom_toTopOf="@+id/quality_group_container"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            />

            <!-- @style/Dialog.Content contains only margins -->
            <ScrollView
                android:id="@+id/quality_group_container"
                style="@style/Dialog.Content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/title_text_view"
                app:layout_constraintBottom_toTopOf="@+id/cancel_button"
                >

                <RadioGroup
                    android:id="@+id/quality_radio_group"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    >
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 1">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 2">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 3">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 4">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 5">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 6">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 7">
                    <RadioButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Option 8">
                </RadioGroup>
            </ScrollView>

        <!-- @style/Dialog.Actions.Button contains margins and paddings -->
        <Button
            android:id="@+id/cancel_button"
            style="@style/Dialog.Actions.Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/device_settings_name_cancel_button_label"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            />

    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>

enter image description here

Please help me to figure out issue using ConstraintLayout.

9
  • I tried that to enable scrolling. It doesn't make any difference though. Updated it. Commented Mar 2, 2018 at 13:45
  • Have a look at This if you already haven't . Commented Mar 2, 2018 at 13:47
  • Try to use NestedScrollView Commented Mar 2, 2018 at 13:50
  • 1
    Set height of ScrollView to 0dp Commented Mar 2, 2018 at 13:57
  • 1
    @PatrykJabłoński Yeah, I know, but setting height=0 will not make ScrollView to occupy remaining space. I tried though, Showing nothing when set to 0. Commented Mar 2, 2018 at 18:31

1 Answer 1

1

I hope this code will helpfull for you

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- @style/Dialog.Title contains margins and font settings -->
    <TextView
        android:id="@+id/title_text_view"
        style="@style/Dialog.Title"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:gravity="center_vertical"
        android:text="@string/device_settings_quality_dialog_title"
        app:layout_constraintBottom_toTopOf="@+id/quality_group_container"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

    <!-- @style/Dialog.Content contains only margins -->
    <ScrollView
        android:id="@+id/quality_group_container"
        style="@style/Dialog.Content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/title_text_view"
        app:layout_constraintBottom_toTopOf="@+id/cancel_button">

        <RadioGroup
            android:id="@+id/quality_radio_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 1"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 2"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 3"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 4"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 5"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 6"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 7"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Option 8"/>
        </RadioGroup>
    </ScrollView>

    <!-- @style/Dialog.Actions.Button contains margins and paddings -->
    <Button
        android:id="@+id/cancel_button"
        style="@style/Dialog.Actions.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/device_settings_name_cancel_button_label"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

</android.support.constraint.ConstraintLayout>

Here I had set attributes of the scrollview as follows

android:layout_height="0dp"
android:layout_weight="1"

This will allocate all remaining space for scrollview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.