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

相关推荐
米码收割机13 小时前
【项目】spring boot+vue3 宠物领养系统(源码+文档)【独一无二】
java·spring boot·宠物
名为沙丁鱼的猫72914 小时前
【审计日志组件实践复盘】前端工程化 + 后端DDD架构(AOP切面拦截日志) + MBG
前端·架构
xqqxqxxq15 小时前
AI智能旅游规划系统 - 前端技术笔记
前端·笔记·旅游
刹那芳华199215 小时前
STMF+ESP-S+MQTT协议连接华为云端(附踩坑记录)
java·struts·华为
就改了20 小时前
Java8 日期处理(详细版)
java·python·算法
麻瓜生活睁不开眼20 小时前
Android16定制SearchLauncher新增投屏Cast桌面快捷图标完整实现
java·launcher·aosp16
陈随易21 小时前
bm2,MoonBit实现的pm2替代品
前端·后端·程序员
ii_best21 小时前
更新!移动端开发软件按键安卓版&手机助手v5.1.0上线!本地AI识别全面解锁,脚本开发再升级
android·人工智能·ios·按键精灵
IT小盘1 天前
12-Prompt不等于一句话-System-User-Context三层结构
java·windows·prompt
方乐寺村1 天前
s,使用libpng提升png图片的保存速度。接下来本文将阐述在Android中如何集成libpng,以及在使用过程中遇到的问题和最 ...
android