约束布局不滚动

Constraint layout doesn't scroll

我已将约束布局放入嵌套滚动视图中以使屏幕可滚动,但它不滚动。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
    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:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/clMain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/dark_blue"
        tools:context=".SignUpActivity"
        >

        <ImageView
            android:id="@+id/ivLogo"
            android:layout_width="@dimen/_148sdp"
            android:layout_height="@dimen/_60sdp"
            android:src="@drawable/logo_voodlee"
            app:layout_constraintVertical_bias="0.08"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <TextView
            android:id="@+id/tvName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name as on Pan Card"
            android:visibility="visible"
            app:fontFamily="@font/poppins_regular"
            android:textColor="@color/fade_green"
            android:textSize="@dimen/_11ssp"
            app:layout_constraintVertical_bias="0.285"
            app:layout_constraintHorizontal_bias="0.135"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <EditText
            android:id="@+id/etName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Name as on Pan Card"
            android:gravity="left"
            android:inputType="textVisiblePassword"
            android:background="@drawable/bg_edittext_thin_line_bright_green"
            android:layout_marginLeft="@dimen/_20sdp"
            android:layout_marginRight="@dimen/_20sdp"
            android:lineSpacingExtra="@dimen/_3sdp"
            app:fontFamily="@font/poppins_regular"
            android:textColor="@color/bright_green"
            android:textColorHint="@color/fade_green"
            android:textSize="@dimen/dimen_20dp"
            android:importantForAutofill="no"
            app:layout_constraintVertical_bias="0.31"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>


        <TextView
            android:id="@+id/tvEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Email"
            android:visibility="visible"
            app:fontFamily="@font/poppins_regular"
            android:textColor="@color/fade_green"
            android:textSize="@dimen/_11ssp"
            app:layout_constraintVertical_bias="0.4"
            app:layout_constraintHorizontal_bias="0.091"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <EditText
            android:id="@+id/etEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textVisiblePassword"
            android:hint="Email"
            android:gravity="left"
            android:background="@drawable/bg_edittext_thin_line_bright_green"
            android:lineSpacingExtra="@dimen/_3sdp"
            app:fontFamily="@font/poppins_regular"
            android:layout_marginLeft="@dimen/_20sdp"
            android:layout_marginRight="@dimen/_20sdp"
            android:textColor="@color/bright_green"
            android:textColorHint="@color/fade_green"
            android:textSize="@dimen/dimen_20dp"
            android:importantForAutofill="no"
            app:layout_constraintVertical_bias="0.43"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <TextView
            android:id="@+id/tvErrorMsgEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="invisible"
            android:text="* Please enter valid email address"
            android:textSize="@dimen/_10ssp"
            android:textColor="@color/voodlee_red"
            app:fontFamily="@font/poppins_regular"
            android:layout_marginTop="@dimen/_4sdp"
            app:layout_constraintHorizontal_bias=".1375"
            app:layout_constraintVertical_bias="0.47"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"

            />

        <TextView
            android:id="@+id/tvMob"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Mobile Number"
            android:gravity="center_vertical"
            android:visibility="visible"
            app:fontFamily="@font/poppins_regular"
            android:textColor="@color/fade_green"
            android:textSize="@dimen/_11ssp"
            app:layout_constraintVertical_bias="0.515"
            app:layout_constraintHorizontal_bias="0.115"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <EditText
            android:id="@+id/etMob"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="phone"
            android:hint="Mobile Number"
            android:gravity="left"
            android:lineSpacingExtra="@dimen/_3sdp"
            android:layout_marginLeft="@dimen/_20sdp"
            android:layout_marginRight="@dimen/_20sdp"
            android:textColor="@color/bright_green"
            android:textColorHint="@color/fade_green"
            android:textSize="@dimen/dimen_20dp"
            app:fontFamily="@font/poppins_regular"
            android:background="@drawable/bg_edittext_thin_line_bright_green"
            android:importantForAutofill="no"
            app:layout_constraintVertical_bias="0.55"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <TextView
            android:id="@+id/tvErrorMsgMobile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="invisible"
            android:text="* Please enter valid mobile number"
            android:textSize="@dimen/_10ssp"
            android:textColor="@color/voodlee_red"
            app:fontFamily="@font/poppins_regular"
            android:layout_marginTop="@dimen/_4sdp"
            app:layout_constraintHorizontal_bias=".135"
            app:layout_constraintVertical_bias="0.5875"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"

            />
  
        <TextView
            android:id="@+id/tvAgree"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="By clicking Proceed you agree to"
            android:textSize="@dimen/dimen_14dp"
            android:textColor="@color/bright_green"
            app:fontFamily="@font/poppins_regular"
            android:gravity="center"
            app:layout_constraintVertical_bias="0.6575"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <TextView
            android:id="@+id/tvAgree2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="the"
            android:textSize="@dimen/dimen_14dp"
            android:textColor="@color/bright_green"
            app:fontFamily="@font/poppins_regular"
            android:gravity="center"
            app:layout_constraintVertical_bias="0.0"
            app:layout_constraintHorizontal_bias="0.125"
            app:layout_constraintLeft_toLeftOf="@id/tvAgree"
            app:layout_constraintRight_toRightOf="@id/tvAgree"
            app:layout_constraintTop_toBottomOf="@id/tvAgree"
            app:layout_constraintBottom_toBottomOf="parent"
            />

        <TextView
            android:id="@+id/tvTnc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Terms and conditions"
            android:textColor="@color/text_highlight"
            android:textSize="@dimen/dimen_14dp"
            app:fontFamily="@font/poppins_regular"
            app:layout_constraintVertical_bias="0.01"
            app:layout_constraintHorizontal_bias="0.2"
            app:layout_constraintLeft_toRightOf="@id/tvAgree2"
            app:layout_constraintRight_toRightOf="@id/tvAgree"
            app:layout_constraintTop_toBottomOf="@id/tvAgree"
            app:layout_constraintBottom_toBottomOf="parent"
            /> 

        <Button
            android:id="@+id/btnNextSignUp"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_36sdp"
            android:background="@drawable/bg_btn_proceed_disabled"
            android:layout_margin="@dimen/_25sdp"
            android:text="Proceed"
            android:textColor="@color/dark_blue"
            android:textAllCaps="false"
            android:textSize="@dimen/dimen_20dp"
            android:onClick="onClickNext"
            android:fontFamily="@font/poppins_semi_bold"
            android:foreground="?attr/selectableItemBackground"
            app:layout_constraintVertical_bias="0.825"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>


        <TextView
            android:id="@+id/tvAlreadyHave"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/text_highlight"
            android:text="Already have an account?"
            app:fontFamily="@font/poppins_regular"
            android:textSize="@dimen/_11sdp"
            android:textStyle="bold"
            app:layout_constraintVertical_bias="0.87"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

               
         <!--Code for Progressbar at bottom of screen-->

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/clProgressSignUp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="visible"
            app:layout_constraintVertical_bias="0.96"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            >

            <ImageView
                android:id="@+id/ivFlowLine"
                android:layout_width="@dimen/_210sdp"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                app:layout_constraintVertical_bias=".425"
                app:layout_constraintHorizontal_bias=".425"
                android:src=
                    "@drawable/bg_flow_line_fade_green"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"

                />

            <ImageView
                android:id="@+id/ivStartCircle"
                android:layout_width="@dimen/_9sdp"
                android:layout_height="@dimen/_9sdp"
                android:src="@drawable/bg_flow_circle_bright_green"
                app:layout_constraintRight_toLeftOf="@id/ivFlowLine"
                app:layout_constraintTop_toTopOf="@id/ivFlowLine"
                app:layout_constraintBottom_toBottomOf="@id/ivFlowLine"/>

            <com.example.voodlee.GradualGrowingLine
                android:id="@+id/ivOrangeLineSignUp"
                android:layout_width="@dimen/_14sdp"
                android:layout_height="@dimen/_3sdp"
                app:startingPoint="0"
                app:layout_constraintVertical_bias=".425"
                app:layout_constraintLeft_toLeftOf="@id/ivStartCircle"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                />


            <ImageView
                android:id="@+id/ivCircle2"
                android:layout_width="@dimen/_16sdp"
                android:layout_height="@dimen/_16sdp"
                android:layout_marginLeft="@dimen/_22sdp"
                app:layout_constraintVertical_bias=".4"
                app:layout_constraintHorizontal_bias="0.43"
                android:src=
                    "@drawable/bg_flow_circle_black"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>

        
            <ImageView
                android:id="@+id/ivCircle5"
                android:layout_width="@dimen/_16sdp"
                android:layout_height="@dimen/_16sdp"

                app:layout_constraintVertical_bias=".4"
                android:src=
                    "@drawable/bg_flow_circle_black"
                app:layout_constraintHorizontal_bias="0.85"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"                  
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>

            <TextView
                android:id="@+id/tvSignUp"                             
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="SignUp"
                android:textSize="@dimen/_9ssp"
                android:textColor="@color/fade_green"
                app:fontFamily="@font/poppins_regular"
                app:layout_constraintLeft_toLeftOf="@id/ivCircle2"
                app:layout_constraintRight_toRightOf="@id/ivCircle2"
                app:layout_constraintTop_toBottomOf="@id/ivCircle2"/>

          
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Autosaving"
                android:textSize="@dimen/_9sdp"
                android:textColor="@color/fade_green"
                app:fontFamily="@font/poppins_regular"
                app:layout_constraintLeft_toLeftOf="@id/ivCircle5"
                app:layout_constraintRight_toRightOf="@id/ivCircle5"
                app:layout_constraintTop_toBottomOf="@id/ivCircle5"
                />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/cl2ProgressSignUp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            app:layout_constraintVertical_bias="0.96"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            >

            <ImageView
                android:id="@+id/iv2FlowLine"
                android:layout_width="@dimen/_210sdp"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                app:layout_constraintVertical_bias=".425"
                app:layout_constraintHorizontal_bias=".425"
                android:src=
                    "@drawable/bg_flow_line_fade_green"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"

                />

            <ImageView
                android:id="@+id/iv2StartCircle"
                android:layout_width="@dimen/_9sdp"
                android:layout_height="@dimen/_9sdp"
                android:src="@drawable/bg_flow_circle_bright_green"
                app:layout_constraintRight_toLeftOf="@id/iv2FlowLine"
                app:layout_constraintTop_toTopOf="@id/iv2FlowLine"
                app:layout_constraintBottom_toBottomOf="@id/iv2FlowLine"/>


            <ImageView
                android:id="@+id/iv2OrangeLine"
                android:layout_width="@dimen/_14sdp"
                android:layout_height="@dimen/_3sdp"
                app:layout_constraintVertical_bias="0.425"
                android:scaleType="centerCrop"
                android:adjustViewBounds="true"
                android:src=
                    "@drawable/bg_flow_line_green_2"
                app:layout_constraintLeft_toLeftOf="@id/iv2StartCircle"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>

                
            <com.example.voodlee.GradualGrowingLine
                android:id="@+id/iv2OrangeLineSignUp"
                android:layout_width="@dimen/_50sdp"
                android:layout_height="@dimen/_3sdp"
                app:startingPoint="14"
                app:layout_constraintVertical_bias=".425"
                app:layout_constraintLeft_toLeftOf="@id/iv2StartCircle"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                />


            <ImageView
                android:id="@+id/iv2Circle2"
                android:layout_width="@dimen/_16sdp"
                android:layout_height="@dimen/_16sdp"
                android:layout_marginLeft="@dimen/_22sdp"
                app:layout_constraintVertical_bias=".4"
                app:layout_constraintHorizontal_bias="0.43"
                android:src=
                    "@drawable/bg_flow_circle_black"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>

           
                 <ImageView
                android:id="@+id/iv2Circle5"
                android:layout_width="@dimen/_16sdp"
                android:layout_height="@dimen/_16sdp"
                app:layout_constraintVertical_bias=".4"
                android:src=
                    "@drawable/bg_flow_circle_black"
                app:layout_constraintHorizontal_bias="0.85"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"                  
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"/>

            <TextView
                android:id="@+id/tv2SignUp"                             
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                androidø:text="SignUp"
                android:textSize="@dimen/_9ssp"
                android:textColor="@color/fade_green"
                app:fontFamily="@font/poppins_regular"
                app:layout_constraintLeft_toLeftOf="@id/iv2Circle2"
                app:layout_constraintRight_toRightOf="@id/iv2Circle2"
                app:layout_constraintTop_toBottomOf="@id/iv2Circle2"/>


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Autosaving"
                android:textSize="@dimen/_9sdp"
                android:textColor="@color/fade_green"
                app:fontFamily="@font/poppins_regular"
                app:layout_constraintLeft_toLeftOf="@id/iv2Circle5"
                app:layout_constraintRight_toRightOf="@id/iv2Circle5"
                app:layout_constraintTop_toBottomOf="@id/iv2Circle5"
                />

        </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

为了确定约束布局是否真的与 Scrollview/Nested Scrollview 一起滚动,我创建了一个简单布局的演示项目,在 Scrollview 中使用约束布局,它确实滚动了。

但我不确定为什么我的具有上述布局的屏幕不滚动。请帮我解决问题。

通过从 NestedScrollview 中删除 android: fillViewPort = "true" 属性并在布局末尾添加一个空视图来解决此问题,如下所示:

<View
    android:id="@+id/view1"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_20sdp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@id/clProgressSignUp"
    />

请尝试下面的滚动约束布局结构。

<LinearLayout>
   
    <androidx.core.widget.NestedScrollView>

        <androidx.constraintlayout.widget.ConstraintLayout>

          ......

        </androidx.constraintlayout.widget.ConstraintLayout>

     </androidx.core.widget.NestedScrollView>

<LinearLayout>