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

标签 android android-nestedscrollview

我正在尝试放置 ConstraintLayoutNestedScrollView 内, 但有一条线将 ConstraintLayout .我不能在那条看不见的线下面放任何东西。我已经尝试了几个小时,但找不到问题。
enter image description here

<?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:tag="layout/fragment_premium"
        app:layout_constraintTop_toTopOf="parent">

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

            <ImageView
                android:id="@+id/launcher_id"
                android:layout_width="185dp"
                android:layout_height="185dp"
                android:layout_marginTop="25dp"
                android:layout_marginBottom="20dp"
                android:contentDescription="TODO"
                app:layout_constraintBottom_toTopOf="@+id/premium_text_id"
                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:layout_marginBottom="220dp"
                android:text="@string/launch_to_premium"
                android:textSize="24sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView2"
                android:layout_width="383dp"
                android:layout_height="196dp"
                android:layout_marginTop="24dp"
                app:layout_constraintBottom_toBottomOf="parent"
                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"在 NestedScrollView

<?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 - 将 ConstraintLayout 放置在 NestedScrollView 中时如何使用整个空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66822156/

相关文章:

android - 折叠工具栏在 coordinatorlayout 中滚动时不折叠

Android:在 NestedScrollView 中滚动以将 View 与可见屏幕顶部对齐

android - 为什么我的 Eclipse 工作区是空的?

android - 嵌套 ScrollView 高度问题

android - FileProvider : Installing APK. 解析包时出错。

android - 在 Android 2.1 中方向更改期间保存 WebView 滚动位置时出现问题

dialog - 安卓 : Custom bottom sheet dialog

android - 将 Android NestedScrollView 水平滑动传递给父 View

Android Bitmap.getPixels 意外的 alpha 值

android-如何向 Realm 数据库添加和删除对象?