简体   繁体   English

ConstraintLayout中的ScrollView无法正常工作

[英]ScrollView inside ConstraintLayout is not working

I have ScrollView and few other views on top and bottom of it, it's inside ConstraintLayout. 我在ScrollView以及它顶部和底部的其他几个视图,它们都在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. 我尝试了很多方法,没有运气,Scrollview会占用全部空间而不是提供滚动,如果对底视图提供了约束,那么该视图将不可见。

XML File: XML档案:

    <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>

在此处输入图片说明

Please help me to figure out issue using ConstraintLayout. 请帮助我找出使用ConstraintLayout的问题。

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 这将为滚动视图分配所有剩余空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM