使用 include 后 ListView 不显示
我现在正在向每个布局添加一个标题,并使用包含来完成它。到目前为止,它一直工作正常,直到我到达列表视图 - 列表视图现在根本不显示!
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#FFFFFF">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/headerbar" layout="@layout/header"
android:layout_height="wrap_content" android:layout_width="fill_parent" />
<ListView android:id="@+id/android:list"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nothin"/>
</LinearLayout>
</ScrollView>
我也尝试过将高度设置为 0dp,但这也不起作用。有人有什么想法吗?
编辑:以下是包含的内容:
<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/headerbg"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:id="@+id/headerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/header"
android:background="@null"></ImageButton>
</LinearLayout>
I am now adding a header to each of my layouts and am doing it with an include. It has so far been working fine until I got to a listview - the listview now doesn't show at all!
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#FFFFFF">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/headerbar" layout="@layout/header"
android:layout_height="wrap_content" android:layout_width="fill_parent" />
<ListView android:id="@+id/android:list"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nothin"/>
</LinearLayout>
</ScrollView>
I've also tried giving a height of 0dp but this hasnt worked either. Does anyone have any ideas?
Edit: heres whats being included:
<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/headerbg"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:id="@+id/headerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/header"
android:background="@null"></ImageButton>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置线性布局的方向属性,以便它知道如何堆叠元素!
You need to set the orientation property of your linearlayout so that it knows how to stack your elements!
难道你的
header
有android:layout_height="fill_parent"
从而使用整个屏幕而没有剩余空间的问题吗?如果情况并非如此,您能否展示如何合并两个布局?
Isn't it the problem that your
header
hasandroid:layout_height="fill_parent"
thus using the whole screen and no space for the rest?If this is not the case, can you show how you are merging both
layouts
?