我有一个RelativeLayout,它包含三个元素:顶部的TableLayout包含一些控件(layout_alignParentTop = true),底部的LinearLayout(layout_alignParentBottom = true),包含一对按钮和在它们之间延伸的ListView(使用layout_below和layout_above这两个元素)。这很好,但在某些情况下,LinearLayout的底部需要消失。如果我使用setVisibility将其设置为View.GONE或使用setLayoutParams()将其高度设置为0,则ListView将顽固地拒绝调整大小以占用新释放的空间。我已经尝试调用requestLayout()基本上在层次结构中的所有内容,似乎没有任何工作。如果我启动层次结构查看器,则可以看到该视图已经消失/具有0的layout_height,但它仍然不起作用。具有讽刺意味的是,在层次结构查看器完成之后,布局会自行修正。不过,我认为让我的用户运行层次结构查看器可能是不可接受的。Android:设置视图高度为0
编辑:中间布局实际上是一个包含ListView的RelativeLayout,这可能很重要,我会尝试并消除它。我已经发布了我的XML的简化版本,可以提供我正在查看的内容。
<RelativeLayout
android:id="@+id/main_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/top_table"
android:layout_alignParentTop="true"
android:stretchColumns="2"
android:shrinkColumns="1">
<!-- removed for simplicity -->
</TableLayout>
<RelativeLayout
android:id="@+id/main_content"
android:descendantFocusability="afterDescendants"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/title_table"
android:layout_above="@id/ad_toolbar">
<!-- removed for simplicity -->
<ListView
android:id="@+id/android:list"
android:layout_alignParentTop="true"
android:descendantFocusability="afterDescendants"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<LinearLayout
android:id="@+id/bottom_layout"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<!-- removed for simplicity -->
</LinearLayout>
</RelativeLayout>
你可以发布.xml的布局吗? – 2010-11-18 01:37:16
实际的XML非常复杂,因为布局由几个由不同活动使用的布局文件组成,但是我已经发布了上面的简化版本。我意识到中间区域实际上是一个包含ListView的RelativeLayout,它可能会有所作为,我将尝试并消除它。 – jjb 2010-11-18 17:51:28