如何使我的 RelativeLayout 可滚动?

How to make my RelativeLayout scrollable?

我为我的项目创建了几个 CardView 并注意到我的页面不可滚动,我搜索并找到了一些方法,例如将 RelativeLayout 更改为 ScrollView 但是当我 运行 我的应用程序时它崩溃了,它在我的 mainActivity java 上出错了。所以我决定把它改回来,把 ScrollView 放在我的 LinearLayout 的顶部,但我的最后一个 CardView 没有完全显示,有些部分隐藏在底部导航后面。有人可以帮助我或启发我如何在 xml 文件中实现 ScrollView 吗?

<RelativeLayout 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"
    android:background="@color/white"
    android:orientation="vertical"
    tools:context=".MainActivity">

 <com.google.android.material.bottomnavigation.BottomNavigationView ...>
 <LinearLayout
            android:id="@+id/frame_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/btm_nav"
            android:orientation="vertical">

 <androidx.appcompat.widget.Toolbar...>

<technolifestyle.com.imageslider.FlipperLayout ...>

<androidx.cardview.widget.CardView ...>

<androidx.cardview.widget.CardView ...>

<androidx.cardview.widget.CardView ...>


        </LinearLayout>

</RelativeLayout>

在其中使用 ScrollView,并使其匹配父项。

将 ScrollView 和 RelativeLayout 的 RelativeLayout 子节点设置为 match_parent。还为 ScrollView

设置 fillviewport = true

将您的 RelativeLayout 放入 ScrollView 中。此外,如果您的最后一张卡片位于 bottomNavigation 后面,请将 android:clipToPadding="false" 属性添加到 ScrollView 并添加一些底部填充。