1

我是 android 应用程序开发的新手。

这是我的 xml 布局文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button 
    android:layout_weight="0.5"
    android:id="@+id/back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/cancel"/>

<Button 
    android:layout_weight="0.5"
    android:layout_gravity="right"
    android:id="@+id/editall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/editall"/>
</LinearLayout>
<ListView 
    android:id="@android:id/list"
    android:cacheColorHint="#00000000"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:fadingEdge="none"/>
</LinearLayout>

在此我可以看到按钮,但未显示列表视图。任何人都可以帮助我吗?提前致谢

4

3 回答 3

4

只需替换wrap_content按钮fill_parent线性布局即可。

改成

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button 
    android:layout_weight="0.5"
    android:id="@+id/back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/cancel"/>

<Button 
    android:layout_weight="0.5"
    android:layout_gravity="right"
    android:id="@+id/editall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/editall"/>
</LinearLayout>
<ListView 
    android:id="@android:id/list"
    android:cacheColorHint="#00000000"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:fadingEdge="none"/>
</LinearLayout>
于 2012-07-16T12:08:41.100 回答
0

将内部线性布局的高度从 fill_parent 更改为 wrap_content。

因为给定高度 fill_parent 将覆盖将隐藏列表视图的父级的整个高度

于 2012-07-16T12:16:00.467 回答
0

您是否也Adapter为您ListView的设置了一个onCreate()?如果它是空的,则屏幕上不会显示任何内容,因为您还使用容器设置了透明背景cacheColorHint并将其应用wrap_content高度。

于 2012-07-16T12:40:20.860 回答