ListView在Android中不可见
我是android应用程序开发新手 这是我的xml布局文件ListView在Android中不可见,android,android-layout,Android,Android Layout,我是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="vertica
<?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>
在这里,我可以看到按钮,但列表视图没有显示。有人能帮我吗。提前感谢只需替换按钮线性布局处的
包装内容
而不是填充父项
改为
<?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>
只需替换按钮线性布局处的
包装内容
而不是填充父项
改为
<?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>
将内部线性布局的高度从填充父级更改为包裹内容
因为给定高度填充父级将覆盖隐藏listview的父级的整个高度将内部线性布局的高度从填充父级更改为换行内容
由于给定高度填充将覆盖隐藏listview的父级的整个高度,因此您是否在
onCreate()中为listview
设置了适配器?如果它是空的,屏幕上将不会显示任何内容,因为您还使用cacheColorHint
设置了透明背景,并将wrap_content
高度应用于它的容器。您是否在onCreate()
中为列表视图设置了适配器?如果它是空的,屏幕上也不会显示任何东西,因为您还使用“代码> CraceCoLoRooStutt设置了一个透明的背景,并且应用了WrAPHythule Lead到它的容器。您可以考虑将代码< > Android:LayOutSuth= =“fILIN Prime/<代码>”用于ListVIEW,因此,它占用了所有剩余的空间,您可以考虑将代码> Android:LayOutSuth= =“fILIN Prime/<代码>”用于ListVIEW,这样就占用了所有剩余的空间。