【问题标题】:How to make my RelativeLayout scrollable? [duplicate]如何使我的 RelativeLayout 可滚动? [复制]
【发布时间】:2020-01-29 04:02:30
【问题描述】:

我为我的项目创建了几个 CardView 并注意到我的页面不可滚动,我搜索并找到了一些方法,例如将 RelativeLayout 更改为 ScrollView 但是当我运行我的应用程序时它崩溃了我的主要活动 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>

【问题讨论】:

    标签: android xml scrollview android-relativelayout


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        将 ScrollView 和 RelativeLayout 的 RelativeLayout 子设置为 match_parent。同时为 ScrollView 设置 fillviewport = true

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-12-17
          • 1970-01-01
          • 1970-01-01
          • 2017-07-05
          • 1970-01-01
          相关资源
          最近更新 更多