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

Android SDK 35下ListView滚动覆盖标题栏问题求助

ListView滚动覆盖标题栏

问题描述

当编译SDK与目标SDK版本为35时,ListView滚动时会覆盖标题栏,使用SDK 34时无此问题。如何让ListView限制在标题栏下方显示?

已尝试以下代码但未解决问题:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    activity.getWindow().setAttributes(new WindowManager.LayoutParams(WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER));
}

解决方法

1. 修正布局约束

确保ListView在布局文件中明确绑定到标题栏下方:

  • 若使用LinearLayout:
    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize" />
    
  • 若使用ConstraintLayout:
    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintTop_toBottomOf="@id/titleBar" />
    

2. 适配WindowInsets

SDK 35对窗口内边距的处理逻辑有调整,通过代码让ListView适配系统栏内边距:

ViewCompat.setOnApplyWindowInsetsListener(listView, (view, insets) -> {
    Insets systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
    view.setPadding(
        view.getPaddingLeft(),
        systemInsets.top,
        view.getPaddingRight(),
        view.getPaddingBottom()
    );
    return insets;
});

3. 检查主题配置

排查Activity主题是否包含android:windowTranslucentStatus、android:windowLayoutInDisplayCutoutMode等可能导致布局延伸的属性,SDK 35下这些属性的生效逻辑可能有变化,可尝试移除或调整对应值。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 05:12:43