android - ScrollView 在添加边距/填充时会导致滚动,即使内容不需要额外空间
问题描述
我正在研究这个布局,其中包含一个滚动视图,其中包含一个线性垂直布局,将图像包裹在顶部和几个文本视图。即使不需要额外的空间来显示内容,滚动也会发生。这是xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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/ToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ShowProfileActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/profile_image_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@string/user_image"
android:scaleType="centerCrop"
android:src="@drawable/user"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/user_info_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="@+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/full_name"
android:textColor="#000000"
android:textSize="24sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="@+id/datebirth"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:autofillHints=""
android:text="@string/birthdate"
android:textColor="#000000"
android:textSize="18sp" />
<TextView
android:id="@+id/gender"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:autofillHints=""
android:text="@string/gender"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:id="@+id/user_nickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/nickname"
android:padding="10dp"
android:text="@string/nickname"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="@+id/user_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_address"
android:inputType="textEmailAddress"
android:padding="10dp"
android:text="@string/email_address"
android:textAllCaps="true"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="italic"
tools:ignore="TextViewEdits" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="@+id/user_state"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:hint="@string/state"
android:text="@string/state"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="@+id/user_city"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:hint="@string/city"
android:text="@string/city"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="italic" />
</LinearLayout>
<TextView
android:id="@+id/user_postal_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/postal_code"
android:padding="10dp"
android:text="@string/postal_code"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="@+id/user_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/address"
android:padding="10dp"
android:text="@string/address"
android:textColor="#000000"
android:textSize="18sp"
android:textStyle="italic" />
</LinearLayout>
</LinearLayout>
</ScrollView>
以下是显示问题的图像。如何防止这种情况发生?我已经为 ScrollView 尝试了一些属性,比如fillViewport
true ,但这没有帮助。
解决方案
推荐阅读
- javascript - Object.assign({}, item) 将对象合并为一个不起作用
- ruby - 如何使用 Ruby 解析特定文件的 git diff?
- android - 一个活动滚动问题中的两个recycleviews
- bash - 通过命令行传递一个数组以使用 getopts() 处理
- python - 用 python / rdflib 解析海龟,不能指定 IRI 前缀
- html - 设置图像的默认大小,如果超过或太小则进行裁剪/放大
- java - 如何通过带有 HATEOAS 的 @JoinTable 获取信息
- node.js - MQTT 订阅者是否需要静态 IP?
- c# - 为什么我的 WebAPI 服务调用无法通过 IIS 找到文件夹路径的一部分?
- c++ - 具有范围的随机数生成器?C++