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 等规则把空间切出来,就不会覆盖。

相关推荐
wearegogog1233 小时前
基于 MATLAB 的卡尔曼滤波器实现,用于消除噪声并估算信号
前端·算法·matlab
韩师学子--小倪3 小时前
fastjson与gson的toString差异
java·json
Drawing stars3 小时前
JAVA后端 前端 大模型应用 学习路线
java·前端·学习
品克缤3 小时前
Element UI MessageBox 增加第三个按钮(DOM Hack 方案)
前端·javascript·vue.js
nbsaas-boot3 小时前
SQL Server 存储过程开发规范(公司内部模板)
java·服务器·数据库
小二·3 小时前
Python Web 开发进阶实战:性能压测与调优 —— Locust + Prometheus + Grafana 构建高并发可观测系统
前端·python·prometheus
小沐°4 小时前
vue-设置不同环境的打包和运行
前端·javascript·vue.js
行百里er4 小时前
用 ThreadLocal + Deque 打造一个“线程专属的调用栈” —— Spring Insight 的上下文管理术
java·后端·架构
玄〤4 小时前
黑马点评中 VoucherOrderServiceImpl 实现类中的一人一单实现解析(单机部署)
java·数据库·redis·笔记·后端·mybatis·springboot
qq_419854054 小时前
CSS动效
前端·javascript·css