Android 在NestedScrollView中放置ConstraintLayout时如何使用整个空间?

Android 在NestedScrollView中放置ConstraintLayout时如何使用整个空间?,android,android-nestedscrollview,Android,Android Nestedscrollview,我试图在嵌套滚动视图中放置一个ConstraintLayout,但是有一行分隔了ConstraintLayout。我不能在那条看不见的线下放任何东西。我已经试了好几个小时了,还是找不到问题 经过一番努力,我终于找到了你想要的东西。关键是在NestedScrollView中使用android:fillViewport=“true” <?xml version="1.0" encoding="utf-8"?> <layout xmlns:a

我试图在
嵌套滚动视图
中放置一个
ConstraintLayout
,但是有一行分隔了
ConstraintLayout
。我不能在那条看不见的线下放任何东西。我已经试了好几个小时了,还是找不到问题


经过一番努力,我终于找到了你想要的东西。关键是在NestedScrollView中使用android:fillViewport=“true”

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <androidx.core.widget.NestedScrollView
        android:id="@+id/premium_layout_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#BFFFFFFF"
        android:focusableInTouchMode="true"
        android:fillViewport="true"
        android:tag="layout/fragment_premium">

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

            <ImageView
                android:id="@+id/launcher_id"
                android:layout_width="180dp"
                android:layout_height="180dp"
                android:layout_marginTop="25dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/launch_premium" />

            <TextView
                android:id="@+id/premium_text_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/launch_to_premium"
                android:textSize="24sp"
                android:layout_marginTop="20dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/launcher_id" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView2"
                android:layout_width="383dp"
                android:layout_height="196dp"
                android:layout_marginTop="24dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/premium_text_id" />

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

您需要在
嵌套滚动视图中添加一个属性
android:fillViewport=“true”

<androidx.core.widget.NestedScrollView
        android:id="@+id/premium_layout_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#BFFFFFFF"
        android:focusableInTouchMode="true"
        android:fillViewport="true" <-- add this
        android:tag="layout/fragment_premium">
博客将对此进行更多解释

<androidx.core.widget.NestedScrollView
        android:id="@+id/premium_layout_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#BFFFFFFF"
        android:focusableInTouchMode="true"
        android:fillViewport="true" <-- add this
        android:tag="layout/fragment_premium">