RelativeLayout 根布局里有一个子布局预期一直展示,但子布局RelativeLayout被 覆盖了

原因一句话 LinearLayout 宽高都是 match_parent,又在 RelativeLayout默认不设置任何相对位置 ,于是它把父布局空间全部占满,之前靠 align*margin 定位的子控件自然被盖住。


解决思路(3 选 1)

  1. 让 LinearLayout 只占剩余区域,而不是全屏 给前面那个需要"一直展示"的控件一个 id,然后让 LinearLayout 用剩余规则:
xml 复制代码
<!-- 顶部固定条,始终可见 -->
<TextView
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:text="标题栏"
    android:gravity="center"
    android:background="@color/colorPrimary"/>

<!-- 内容区,只占剩余 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_below="@id/title"      <!-- 关键:在标题下方 -->
    android:orientation="vertical">
    <!-- 你的内容 -->
</LinearLayout>
  1. 把 LinearLayout 改成 wrap_content 或固定值 如果你只是想弹个面板,就别让它 match_parent
xml 复制代码
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:orientation="vertical">
  1. layout_weight(嵌套一层 LinearLayout) 顶层改成横向或纵向 LinearLayout,把"始终展示"的 view 放 weight=0,内容区放 weight=1 即可。

一句话总结 别让 LinearLayout 又满屏又不相对定位 ;给前面控件加 id,再用 layout_below / layout_above / layout_alignParentBottom 等规则把空间切出来,就不会覆盖。

相关推荐
linweidong3 小时前
C++ 模块化编程(Modules)在大规模系统中的实践难点?
linux·前端·c++
leobertlan6 小时前
2025年终总结
前端·后端·程序员
子兮曰7 小时前
OpenClaw架构揭秘:178k stars的个人AI助手如何用Gateway模式统一控制12+通讯频道
前端·javascript·github
百锦再7 小时前
Reactive编程入门:Project Reactor 深度指南
前端·javascript·python·react.js·django·前端框架·reactjs
莲华君7 小时前
React快速上手:从零到项目实战
前端·reactjs教程
百锦再7 小时前
React编程高级主题:测试代码
android·前端·javascript·react.js·前端框架·reactjs
易安说AI8 小时前
Ralph Loop 让Claude无止尽干活的牛马...
前端·后端
JH30738 小时前
SpringBoot 优雅处理金额格式化:拦截器+自定义注解方案
java·spring boot·spring
2501_916008899 小时前
全面介绍Fiddler、Wireshark、HttpWatch、SmartSniff和firebug抓包工具功能与使用
android·ios·小程序·https·uni-app·iphone·webview
Coder_Boy_9 小时前
技术让开发更轻松的底层矛盾
java·大数据·数据库·人工智能·深度学习