在约束布局中使用 NestedScrollView 的问题

Problem in using NestedScrollView in Constraint layout

我在 NestestScrollView 中使用 Constraint 布局,如下所示。

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/clProfileFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/appCompatImageView8"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:scaleType="centerCrop"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHeight_percent="0.7"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@mipmap/bg_nature" />


<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/ivProfileFragment"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:src="@drawable/ic_profile"
    android:visibility="visible"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/tvUserName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:fontFamily="@font/raleway_medium"
    android:letterSpacing="0.2"
    android:textAlignment="center"
    android:textColor="@color/darkBlue"
    app:layout_constraintBottom_toBottomOf="@+id/ivProfileFragment"
    app:layout_constraintStart_toEndOf="@+id/ivProfileFragment"
    app:layout_constraintTop_toTopOf="@+id/ivProfileFragment"
    tools:text="Mehul Kanzriya" />


<androidx.appcompat.widget.AppCompatImageView
    android:id="@+id/ivCloseProfileFragment"
    style="@style/VectorImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_close" />

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:fillViewport="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/ivProfileFragment"
    app:layout_constraintBottom_toTopOf="@id/button">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="32dp"
            android:layout_marginEnd="8dp"
            android:fontFamily="@font/raleway_semibold"
            android:letterSpacing="0.3"
            android:text="@string/text_subscribe"
            android:textColor="@color/darkBlue"
            android:textSize="18sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:letterSpacing="0.3"
            android:text="@string/text_subscription_feature_1"
            android:textAlignment="center"
            android:textColor="@color/subscriptionFeaturesColor"
            android:textSize="@dimen/subscriptionFeaturesSize"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:letterSpacing="0.3"
            android:text="@string/text_subscription_feature_2"
            android:textAlignment="center"
            android:textColor="@color/subscriptionFeaturesColor"
            android:textSize="@dimen/subscriptionFeaturesSize"
            app:layout_constraintEnd_toEndOf="@+id/textView2"
            app:layout_constraintStart_toStartOf="@+id/textView2"
            app:layout_constraintTop_toBottomOf="@+id/textView2" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:letterSpacing="0.3"
            android:text="@string/text_subscription_feature_3"
            android:textAlignment="center"
            android:textColor="@color/subscriptionFeaturesColor"
            android:textSize="@dimen/subscriptionFeaturesSize"
            app:layout_constraintEnd_toEndOf="@+id/textView4"
            app:layout_constraintStart_toStartOf="@+id/textView4"
            app:layout_constraintTop_toBottomOf="@+id/textView4" />

        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/appCompatImageView2"
            android:layout_width="350dp"
            android:layout_height="168dp"
            android:layout_marginTop="32dp"
            app:layout_constraintEnd_toEndOf="@+id/textView5"
            app:layout_constraintStart_toStartOf="@+id/textView5"
            app:layout_constraintTop_toBottomOf="@+id/textView5"
            app:srcCompat="@mipmap/bg_pdf_resting" />

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/cvAnnualPlan"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            app:cardBackgroundColor="@android:color/transparent"
            app:cardCornerRadius="14dp"
            app:cardElevation="0dp"
            app:layout_constraintEnd_toStartOf="@+id/cvMonthlyPlan"
            app:layout_constraintHorizontal_chainStyle="spread"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/appCompatImageView2"
            app:strokeColor="@color/darkBlue"
            app:strokeWidth="3dp">

            <com.google.android.material.card.MaterialCardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                app:cardBackgroundColor="@color/subscriptionCardBackgroundColor"
                app:cardCornerRadius="12dp"
                app:cardElevation="0dp">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">


                    <TextView
                        android:id="@+id/textView7"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:background="@color/darkBlue"
                        android:fontFamily="@font/raleway_medium"
                        android:letterSpacing="0.1"
                        android:padding="8dp"
                        android:text="@string/text_subscription_most_popular"
                        android:textAlignment="center"
                        android:textColor="@android:color/white"
                        android:textSize="12sp"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="32dp"
                        android:layout_marginEnd="8dp"
                        android:fontFamily="@font/raleway_semibold"
                        android:letterSpacing="0.3"
                        android:text="ANNUAL"
                        android:textColor="@color/lightYellow"
                        android:textSize="@dimen/subscriptionPlanTitle"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/textView7" />

                    <TextView
                        android:id="@+id/textView6"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="8dp"
                        android:fontFamily="@font/roboto_bold"
                        android:text="Rs 60.00"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/subscriptionPlanPrice"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/textView3" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="8dp"
                        android:layout_marginEnd="8dp"
                        android:layout_marginBottom="32dp"
                        android:fontFamily="@font/raleway_semibold"
                        android:letterSpacing="0.3"
                        android:text="@string/text_per_month"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/subscriptionPlanMonthly"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/textView6" />

                </androidx.constraintlayout.widget.ConstraintLayout>

            </com.google.android.material.card.MaterialCardView>
        </com.google.android.material.card.MaterialCardView>

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/cvMonthlyPlan"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            app:cardBackgroundColor="@android:color/transparent"
            app:cardCornerRadius="14dp"
            app:cardElevation="0dp"
            app:layout_constraintBottom_toBottomOf="@+id/cvAnnualPlan"
            app:layout_constraintEnd_toEndOf="parent"

            app:layout_constraintStart_toEndOf="@+id/cvAnnualPlan"
            app:layout_constraintTop_toTopOf="@+id/cvAnnualPlan"
            app:strokeColor="@color/darkBlue"
            app:strokeWidth="3dp">

            <com.google.android.material.card.MaterialCardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="2dp"
                app:cardBackgroundColor="@color/subscriptionCardBackgroundColor"
                app:cardCornerRadius="12dp"
                app:cardElevation="0dp">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">


                    <TextView
                        android:id="@+id/textView8"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:padding="8dp"
                        android:textSize="12sp"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <TextView
                        android:id="@+id/textView44"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="32dp"
                        android:layout_marginEnd="8dp"
                        android:fontFamily="@font/raleway_semibold"
                        android:letterSpacing="0.3"
                        android:text="MONTHLY"
                        android:textColor="@color/lightYellow"
                        android:textSize="@dimen/subscriptionPlanTitle"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/textView8" />

                    <TextView
                        android:id="@+id/textView66"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="8dp"
                        android:fontFamily="@font/roboto_bold"
                        android:text="Rs 70.00"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/subscriptionPlanPrice"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/textView44" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="8dp"
                        android:layout_marginEnd="8dp"
                        android:layout_marginBottom="32dp"
                        android:fontFamily="@font/raleway_semibold"
                        android:letterSpacing="0.3"
                        android:text="@string/text_per_month"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/subscriptionPlanMonthly"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/textView66" />

                </androidx.constraintlayout.widget.ConstraintLayout>

            </com.google.android.material.card.MaterialCardView>
        </com.google.android.material.card.MaterialCardView>

        <TextView
            android:id="@+id/textView9"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="8dp"
            android:letterSpacing="0.3"
            android:text="@string/text_subscription_feature_4"
            android:textAlignment="center"
            android:textColor="@color/subscriptionFeaturesColor"
            android:textSize="@dimen/subscriptionFeaturesSize"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cvAnnualPlan" />

        <TextView
            android:id="@+id/textView10"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:letterSpacing="0.3"
            android:text="@string/text_subscription_feature_5"
            android:textAlignment="center"
            android:textColor="@color/subscriptionFeaturesColor"
            android:textSize="@dimen/subscriptionFeaturesSize"
            app:layout_constraintEnd_toEndOf="@+id/textView9"
            app:layout_constraintStart_toStartOf="@+id/textView9"
            app:layout_constraintTop_toBottomOf="@+id/textView9" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="16dp"
            android:fontFamily="@font/raleway_semibold"
            android:letterSpacing="0.3"
            android:text="@string/button_logout"
            android:textAlignment="center"
            android:textColor="@color/logoutButtonColor"
            android:textSize="@dimen/subscriptionFeaturesSize"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@+id/textView10"
            app:layout_constraintStart_toStartOf="@+id/textView10"
            app:layout_constraintTop_toBottomOf="@+id/textView10" />

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

<Button
    android:id="@+id/button"
    style="@style/UnelevatedButton"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="@string/button_subscribe"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

问题是前两个 TextView 被裁剪,并且在 NestedScrollView 的底部添加了不必要的填充。

A​​ similar bug 是几个月前提交的,但我认为它尚未解决。

之前也有人问过类似的问题,但是我找不到合适的解决方法。

看看嵌套在 NestedScrollView 中的 ConstraintLayout 上的 android:layout_gravity="center"。尝试删除此属性或将其设置为 android:layout_gravity="center_horizonal"。我不太确定在 NestedScrollView.

中垂直居中 View 是什么意思

试试这个结果 https://www.youtube.com/watch?v=PTnbzCbgBTE

  <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/clProfileFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/appCompatImageView8"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHeight_percent="0.7"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@color/colorAccent" />


        <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/ivProfileFragment"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:src="@drawable/ic_launcher_nilesh"
            android:visibility="visible"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tvUserName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:letterSpacing="0.2"
            android:textAlignment="center"
            app:layout_constraintBottom_toBottomOf="@+id/ivProfileFragment"
            app:layout_constraintStart_toEndOf="@+id/ivProfileFragment"
            app:layout_constraintTop_toTopOf="@+id/ivProfileFragment"
            android:text="Mehul Kanzriya" />


        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/ivCloseProfileFragment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_drawer" />

        <androidx.core.widget.NestedScrollView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:clipToPadding="true"
            android:fillViewport="true"
            android:fitsSystemWindows="true"
            app:layout_constraintBottom_toTopOf="@id/button"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/ivProfileFragment">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal">

                <TextView
                    android:id="@+id/textView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="32dp"
                    android:layout_marginEnd="8dp"
                    android:letterSpacing="0.3"
                    android:text="text_subscribe"
                    android:textSize="18sp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="16dp"
                    android:letterSpacing="0.3"
                    android:text="text_subscription_feature_1"
                    android:textAlignment="center"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textView" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:letterSpacing="0.3"
                    android:text="text_subscription_feature_2"
                    android:textAlignment="center"
                    app:layout_constraintEnd_toEndOf="@+id/textView2"
                    app:layout_constraintStart_toStartOf="@+id/textView2"
                    app:layout_constraintTop_toBottomOf="@+id/textView2" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="0dp"
                    android:layout_height="16dp"
                    android:layout_marginTop="8dp"
                    android:letterSpacing="0.3"
                    android:text="text_subscription_feature_3"
                    android:textAlignment="center"
                    app:layout_constraintEnd_toEndOf="@+id/textView4"
                    app:layout_constraintStart_toStartOf="@+id/textView4"
                    app:layout_constraintTop_toBottomOf="@+id/textView4" />

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/appCompatImageView2"
                    android:layout_width="350dp"
                    android:layout_height="168dp"
                    android:layout_marginTop="32dp"
                    app:layout_constraintEnd_toEndOf="@+id/textView5"
                    app:layout_constraintStart_toStartOf="@+id/textView5"
                    app:layout_constraintTop_toBottomOf="@+id/textView5"
                    app:srcCompat="@mipmap/ic_launcher_round" />

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/cvAnnualPlan"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="16dp"
                    app:cardBackgroundColor="@android:color/transparent"
                    app:cardCornerRadius="14dp"
                    app:cardElevation="0dp"
                    app:layout_constraintEnd_toStartOf="@+id/cvMonthlyPlan"
                    app:layout_constraintHorizontal_chainStyle="spread"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/appCompatImageView2"
                    app:strokeWidth="3dp">

                    <com.google.android.material.card.MaterialCardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="2dp"
                        app:cardCornerRadius="12dp"
                        app:cardElevation="0dp">

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">


                            <TextView
                                android:id="@+id/textView7"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:letterSpacing="0.1"
                                android:padding="8dp"
                                android:text="text_subscription_most_popular"
                                android:textAlignment="center"
                                android:textColor="@android:color/white"
                                android:textSize="12sp"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent" />

                            <TextView
                                android:id="@+id/textView3"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="32dp"
                                android:layout_marginEnd="8dp"
                                android:letterSpacing="0.3"
                                android:text="ANNUAL"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toBottomOf="@+id/textView7" />

                            <TextView
                                android:id="@+id/textView6"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="16dp"
                                android:layout_marginEnd="8dp"
                                android:text="Rs 60.00"
                                android:textColor="@android:color/white"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toBottomOf="@+id/textView3" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="8dp"
                                android:layout_marginEnd="8dp"
                                android:layout_marginBottom="32dp"
                                android:letterSpacing="0.3"
                                android:text="text_per_month"
                                android:textColor="@android:color/white"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toBottomOf="@+id/textView6" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </com.google.android.material.card.MaterialCardView>
                </com.google.android.material.card.MaterialCardView>

                <com.google.android.material.card.MaterialCardView
                    android:id="@+id/cvMonthlyPlan"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp"
                    app:cardBackgroundColor="@android:color/transparent"
                    app:cardCornerRadius="14dp"
                    app:cardElevation="0dp"
                    app:layout_constraintBottom_toBottomOf="@+id/cvAnnualPlan"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toEndOf="@+id/cvAnnualPlan"
                    app:layout_constraintTop_toTopOf="@+id/cvAnnualPlan"
                    app:strokeWidth="3dp">

                    <com.google.android.material.card.MaterialCardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="2dp"
                        app:cardCornerRadius="12dp"
                        app:cardElevation="0dp">

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">


                            <TextView
                                android:id="@+id/textView8"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:padding="8dp"
                                android:textSize="12sp"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent" />

                            <TextView
                                android:id="@+id/textView44"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="32dp"
                                android:layout_marginEnd="8dp"
                                android:letterSpacing="0.3"
                                android:text="MONTHLY"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toBottomOf="@+id/textView8" />

                            <TextView
                                android:id="@+id/textView66"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="16dp"
                                android:layout_marginEnd="8dp"
                                android:text="Rs 70.00"
                                android:textColor="@android:color/white"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toBottomOf="@+id/textView44" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="8dp"
                                android:layout_marginEnd="8dp"
                                android:layout_marginBottom="32dp"
                                android:letterSpacing="0.3"
                                android:text="text_per_month"
                                android:textColor="@android:color/white"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toBottomOf="@+id/textView66" />

                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </com.google.android.material.card.MaterialCardView>
                </com.google.android.material.card.MaterialCardView>

                <TextView
                    android:id="@+id/textView9"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="8dp"
                    android:letterSpacing="0.3"
                    android:text="text_subscription_feature_4"
                    android:textAlignment="center"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/cvAnnualPlan" />

                <TextView
                    android:id="@+id/textView10"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:letterSpacing="0.3"
                    android:text="text_subscription_feature_5"
                    android:textAlignment="center"
                    app:layout_constraintEnd_toEndOf="@+id/textView9"
                    app:layout_constraintStart_toStartOf="@+id/textView9"
                    app:layout_constraintTop_toBottomOf="@+id/textView9" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="16dp"
                    android:letterSpacing="0.3"
                    android:text="button_logout"
                    android:textAlignment="center"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="@+id/textView10"
                    app:layout_constraintStart_toStartOf="@+id/textView10"
                    app:layout_constraintTop_toBottomOf="@+id/textView10" />

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

        <Button
            android:id="@+id/button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="button_subscribe"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

在我的情况下,ConstraintLayout 的子视图中有一个app:layout_constraintBottom_toBottomOf="parent"

                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/choose_position"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.061"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/chip_group_time"
                    app:layout_constraintVertical_bias="0.027" />

删除layout_constrainBottom_toBottomOf。我的 NestedScrollView 工作!!!

                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/choose_position"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.061"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/chip_group_time"
                    app:layout_constraintVertical_bias="0.027" />

注意在 NestedScrollView > ConstraintLayout 中使用 app:layout_constraintBottom_toBottomOf="parent"。因为它使布局固定