我想做一个选择ListActivity,类似于用于向快速启动屏幕添加快捷方式的选项。我已经推出了自己的页眉和页脚,我希望在屏幕上在视图的顶部和底部“粘”。为了做到这一点,我使用了一个RelativeLayout,头部设置为顶部,页脚设置为底部,列表设置为低于页眉和页脚上方。就整个活动的布局而言,这是我所期望的渲染。标题粘到顶部,页脚粘到底部,列表滚动到它们之间。Android的RelativeLayout和wrap_content的高度?
当我切换到RelativeLayout作为我的根时发生了一件奇怪的事情。请看下面的截图:
我想我的活动的身高是wrap_content
,这样的形式是只高在它显示的内容,但一旦我切换到RelativeLayout的,似乎呈现该活动有效地作为fill_parent
,占据整个屏幕,即使内容不保证。请注意,没有足够的列表项填充屏幕,其中fill_parent
样式会在列表末尾和页脚之间留下一堆空白。我正在通过样式设置我的高度 - 这与LinearLayout运行良好,但现在似乎被忽略。所以我试着直接在RelativeLayout上硬编码高度,但它仍然不起作用,仍然呈现为fill_parent
。
这里是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/GroupsList"
android:layout_height="wrap_content">
<FrameLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/hdrGroups"
android:layout_alignParentTop="true">
<include layout="@layout/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</include>
</FrameLayout>
<FrameLayout style="@style/MyFooter"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/ftrGroups">
<ImageView style="@style/CloseButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/add"
android:id="@+id/imgGroupsAdd"
android:clickable="true">
</ImageView>
</FrameLayout>
<ListView android:divider="#9f9f9f"
android:id="@+id/android:list"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/hdrGroups"
android:layout_above="@id/ftrGroups">
</ListView>
<TextView android:text="@string/browser_no_groups"
style="@style/ListedItemB"
android:id="@+id/android:empty"
android:layout_height="wrap_content"
android:layout_above="@id/ftrGroups"
android:layout_below="@id/hdrGroups"
android:layout_width="fill_parent">
</TextView>
</RelativeLayout>
所有的布局是通过XML完成的,......我不是在做任何代码的布局。 如何获得粘性页眉和页脚,同时使整个活动在wrap_content
模式下表现出高度?有没有其他方式我应该去关于这个而不是RelativeLayout?
您能够发布更完整的代码示例复制截图和问题?我的朋友和我有一个想法,但我们懒得把你没有提供的遗失物品放在一起。 –
我会在接下来的几天里看看我能不能把东西扔在一起。 – eidylon
嗯,我终于有机会,并举了一个例子...在这里找到它:http://dl.dropbox.com/u/19767586/layout.test.zip。我还包括两个屏幕,一个是它的外观,一个是它应该看起来像。 – eidylon