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.

Bipin Vayalu
  • 2,671
  • 1
  • 21
  • 32
  • I tried that to enable scrolling. It doesn't make any difference though. Updated it. – Bipin Vayalu Mar 02 '18 at 13:45
  • Have a look at [This](https://stackoverflow.com/questions/42453367/scrollview-inside-constraint-layout-does-not-scroll-to-the-bottom-of-the-parent) if you already haven't . – ADM Mar 02 '18 at 13:47
  • Try to use NestedScrollView – Pavel Poley Mar 02 '18 at 13:50
  • 1
    Set height of `ScrollView` to `0dp` – Patryk Jabłoński Mar 02 '18 at 13:57
  • @ADM I tried that, the Main difference in this is there is no view after ScrollView. – Bipin Vayalu Mar 02 '18 at 15:26
  • @PatrykJabłoński `ScrollView height 0dp` will not get any space. Because here we are not having any `layout_weight` things. – Bipin Vayalu Mar 02 '18 at 15:32
  • @PavelPoley NestedScrollView is used when we need Scrollview inside another ScrollView. Ref: https://stackoverflow.com/questions/34773982/android-scrollview-vs-nestedscrollview – Bipin Vayalu Mar 02 '18 at 15:33
  • @Bipin Vayalu `ConstraintLayout` has nothing to `layout_weight`. `layout_weight` is used by `LinearLayout`. Have you tried my suggestion? If you will set there `0dp` it should fit the size that is limited by your constraints. When you use wrap-content it will fit content size which in this case is not wanted – Patryk Jabłoński Mar 02 '18 at 16:20
  • @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. – Bipin Vayalu Mar 02 '18 at 18:31

1 Answers1

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

NIKHIL NEDIYODATH
  • 1,139
  • 2
  • 16
  • 25