如何将项目从;包装“U内容”;在Android视图中?

如何将项目从;包装“U内容”;在Android视图中?,android,android-layout,android-view,Android,Android Layout,Android View,我在标题中有一个下拉菜单。当按下按钮时,下拉菜单下降。问题是,活动中的所有其他视图都是使用android:layout_down=“@id/header”定位的,下拉菜单会向下推所有视图,因为它会增加页眉的高度。我需要从android:layout\u height=“wrap\u content”中排除下拉菜单,以防止出现这种情况。可能吗 注意:我可以通过编程解决这个问题,我只想了解是否可以从XML中的“扭曲内容”中排除项目。从一个RelativeLayout开始,然后在RelativeLay

我在标题中有一个下拉菜单。当按下按钮时,下拉菜单下降。问题是,活动中的所有其他视图都是使用
android:layout_down=“@id/header”
定位的,下拉菜单会向下推所有视图,因为它会增加页眉的高度。我需要从android:layout\u height=“wrap\u content”中排除下拉菜单,以防止出现这种情况。可能吗


注意:我可以通过编程解决这个问题,我只想了解是否可以从XML中的“扭曲内容”中排除项目。

从一个
RelativeLayout
开始,然后在
RelativeLayout
中添加所有项目,最后,将头文件放在XML的底部(在底部的意思是,它将显示在所有其他元素上)。例如:

<!-- Root element -->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- First text view, the margin_top defines space for your header -->
    <TextView android:id="@+id/tv1" android:layout_margin_top="height_of_your_header"/>

    <!-- TextView below another view -->
    <TextView android:id="@+id/tv2" android:layout_below="@+id/tv1" />

    <!-- Your Header file, which will be positioned over all elements
    - When closed, it will fit above @id/tv1
    - When opened, it will float above the other elements -->
    <include
        layout="@layout/header" 
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>


除非设置了
android:visibility=gone
,否则在布局计算过程中不能排除ViewGroup的子级。但是,您可能需要将主容器替换为
RelativeLayout
,这样您就可以根据自己的意愿定位某些元素了。

您想说什么。.澄清它。希望添加更多文本更清晰。好的,修改它。如果它仍然不清晰,请告诉我,我将重试:)。页眉的高度根据png文件的不同在不同的屏幕上变化,我不能为android:layout\u margin\u top使用常量值。我想我最终会以编程方式设置高度。无论如何,谢谢。如果是这样的话,你应该通过编程来实现最简单的方法。是的,我最终通过编程来设置高度。谢谢你的帮助!是的,我最初使用的是android:visibility=gone,但当我需要显示下拉菜单时,我会通过编程将值更改为“visible”,这会弄乱高度。我已经使用了RelativeLayout。谢谢你的回答。至少现在我知道不可能从“包装内容”中排除项目。