android - ListView 在 Android 中不可见

标签 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="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>

在这里我可以看到按钮,但 ListView 没有显示。任何人都可以帮助我吗?提前致谢

最佳答案

只需将 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>

关于android - ListView 在 Android 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11503950/

相关文章:

java - Realm.io 无法让示例正常工作

android - onSaveInstanceState 不能保存静态变量?

java - 如何在 9patch 上正确应用 adjust_pan?

android - 如何杀死其他应用程序Android

android - 如何解决gradle错误

android - SimpleDateFormat 只获取时间

android - 如何在 ActionBar 溢出菜单中显示图标?

android - EditText setError 在 BottomSheetDialog 中不合适

android - 在 Android 的线程中运行 ProgressDialog

android - 按钮在 Android 中显示键盘时更改其位置