LinearLayout布局异常求助:doView未显示在Linear1下方
布局修正方案
核心问题就是你发现的那个多余</LinearLayout>标签——它错误地将doView的LinearLayout包裹进了fsView的LinearLayout内部,导致RelativeLayout的android:layout_below属性完全失效,所以doView才会显示在Linear1里面而非下方。
修正步骤很直接:
- 找到
fsView对应的LinearLayout代码块,删除那个多余的</LinearLayout>闭合标签 - 确保
doView的LinearLayout是直接嵌套在最外层的RelativeLayout之下,和Linear1、fsView处于同一层级
错误结构简化示例:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/Linear1" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- 图片展示区域 --> </LinearLayout> <LinearLayout android:id="@+id/fsView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/Linear1" android:visibility="gone"> <!-- fsView内容 --> </LinearLayout> </LinearLayout> <!-- 这里是多余的闭合标签 --> <LinearLayout android:id="@+id/doView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/Linear1" android:visibility="gone"> <!-- doView内容 --> </LinearLayout> </RelativeLayout>
正确结构简化示例:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/Linear1" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- 图片展示区域 --> </LinearLayout> <LinearLayout android:id="@+id/fsView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/Linear1" android:visibility="gone"> <!-- fsView内容 --> </LinearLayout> <LinearLayout android:id="@+id/doView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/Linear1" android:visibility="gone"> <!-- doView内容 --> </LinearLayout> </RelativeLayout>
修改完成后,doView就处于RelativeLayout的直接子层级,layout_below属性会正常生效,它就能正确显示在Linear1的下方了。
内容的提问来源于stack exchange,提问作者KiDo
相关产品推荐
相关产品推荐

