java - 当可滚动的 recyclerView 仅占手机屏幕的一半时,如何让 Activity 中的整个屏幕滚动

标签 java android xml

我希望整个屏幕滚动,但目前只有我的回收器会滚动。尽管所有元素都放置在 ScrollView 内的线性布局中,但还是会发生这种情况。

有什么想法错误在哪里吗?这是相关代码。

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".NoodleDetailActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/noodleImage"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:adjustViewBounds="false"
                android:scaleType="centerCrop"
                app:srcCompat="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/border_bottom"
                android:fontFamily="sans-serif-smallcaps"
                android:hapticFeedbackEnabled="false"
                android:padding="30dp"
                android:text="TextView"
                android:textSize="18sp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/extras_recycler"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="0dp"
                android:background="#F2F2F2"
                android:padding="0dp" />
        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

这就是它的视觉效果。

demo appearance

最佳答案

发现:似乎最佳实践是将recyclerView设置为整个布局并使其包含多种 View 类型。 我不会使用嵌套 ScrollView 。

关于java - 当可滚动的 recyclerView 仅占手机屏幕的一半时,如何让 Activity 中的整个屏幕滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58235317/

相关文章:

android - 复选框上下文菜单

java - 使用与时间相对应的 Csv 文件获取奇怪的输出

java - 如何使用 Jackson 将其序列化为 xml?

android - 无法在 Android (Kotlin) 中使用 ObjectBox 保存相同的数据

c++ - 读取 XML 文件中存储的业务规则的优雅方式

c# - 如何获取 XML 属性的值?

xml - Magento 缓存没有被清除

java - 无法在另一台 PC 上运行 JAR 文件。环境变量可能有问题?

java - 循环结构,很困惑

android - Activity 无法解析或不是字段