You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通知栏下方空白区域遮挡界面元素问题求助

解决通知栏下方空白遮挡界面元素的问题

问题原因

  1. CoordinatorLayout设置了android:fitsSystemWindows="true",会为系统状态栏预留空间,但内部ScrollView未适配该设置,导致内容布局未避开状态栏区域。
  2. 内层LinearLayout设置了android:layout_gravity="center",强制内容垂直居中,结合ScrollView的wrap_content高度设置,使得顶部出现空白区域,且无法向上滚动调整位置。

修复方案

  • 移除LinearLayout的android:layout_gravity="center"属性,让内容从顶部开始排列。
  • 给ScrollView添加android:fitsSystemWindows="true",确保内容在状态栏下方正常布局。
  • 将ScrollView的android:layout_height从wrap_content改为match_parent,保证滚动区域填充整个可用空间。

修改后的完整布局代码

<androidx.coordinatorlayout.widget.CoordinatorLayout 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/background"
    tools:context=".MainActivity"
    android:fitsSystemWindows="true">

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

        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:gravity="center_horizontal"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:orientation="vertical">

            <androidx.cardview.widget.CardView
                android:layout_marginTop="4dp"
                android:layout_height="170dp"
                android:layout_width="match_parent"
                app:cardCornerRadius="20dp"
                android:backgroundTint="@color/note1"/>

            <androidx.cardview.widget.CardView
                android:layout_marginTop="4dp"
                android:layout_height="170dp"
                android:layout_width="match_parent"
                app:cardCornerRadius="20dp"
                android:backgroundTint="@color/note2"/>

            <androidx.cardview.widget.CardView
                android:layout_marginTop="4dp"
                android:layout_height="170dp"
                android:layout_width="match_parent"
                app:cardCornerRadius="20dp"
                android:backgroundTint="@color/note3"/>

            <androidx.cardview.widget.CardView
                android:layout_marginTop="4dp"
                android:layout_height="170dp"
                android:layout_width="match_parent"
                app:cardCornerRadius="20dp"
                android:backgroundTint="@color/note4"/>

            <androidx.cardview.widget.CardView
                android:layout_marginTop="4dp"
                android:layout_height="170dp"
                android:layout_width="match_parent"
                app:cardCornerRadius="20dp"
                android:backgroundTint="@color/note5"/>

        </LinearLayout>
    </ScrollView>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="@dimen/fab_margin"
        android:layout_marginBottom="16dp"
        android:backgroundTint="@color/floating_button"
        app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

内容的提问来源于stack exchange,提问作者user14366507

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 23:54:55