android - 将 ConstraintLayout 放置在 NestedScrollView 中时如何使用整个空间?
问题描述
我试图把 a 放在 aConstraintLayout
里面NestedScrollView
,但是有一条线将ConstraintLayout
. 我不能在那条看不见的线下面放任何东西。我已经尝试了几个小时,但找不到问题。
<?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
<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">
为什么?
fillViewport
在滚动视图的子视图高度较小的情况下,允许 NestedScrollView 将其高度扩展为设备屏幕高度的完整高度。
这个博客将对此进行更多解释。
推荐阅读
- python - 使用函数时将结果输入到 df
- hadoop - 从客户端应用程序写入的 Google Dataproc 将集群的内部 IP 用于 Datanodes
- html - 汉堡菜单导航(小问题)
- terraform - 通过 Terraform 运行“aws stepfunctions update-state-machine”时出现 Json 解析错误
- flutter - Flutter / FireStore : 获取刚刚在 Collection 中创建的文档的 ID
- python - 用字典替换熊猫数据框中的值
- android - Android 10 中的 Android 文件复制问题
- sql - 如何将小于、大于、等于 <、>、= 转换为 SQL Server
- docker - 基于另一个服务启动一个docker服务
- node.js - 快递:request.body 未定义