【问题标题】:ListView not showing items on a smaller screenListView 未在较小的屏幕上显示项目
【发布时间】:2013-01-31 16:56:58
【问题描述】:

我有一个屏幕更大的模拟器,一切正常。 ListView 显示一切正常,因此不在 java 代码中。我现在尝试在 3.2 屏幕上对其进行测试,ListView 没有显示任何内容。我尝试使用较小的屏幕 (3.2) 模拟器,但它也没有显示任何内容,所以我猜这与他们的布局有关。

我的 listview.xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="150dp" >

    </ListView>

</LinearLayout>

行 xml 文件:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/text1"
        android:layout_width="match_parent"        
        android:gravity="center"
        android:layout_height="30dp" />

</LinearLayout>

【问题讨论】:

  • 您的 imo 布局没有问题。
  • @Aerilys 我也是这么想的。但一切都在更大的屏幕上运行,那么问题出在哪里?

标签: java android xml layout screen-size


【解决方案1】:

您不应该将 android:layout_width 和 android:layout_height 设置为 ListView 的 wrap_content。

【讨论】:

  • 其实layout_height可以是wrap_content。关于 layout_width 是真的。
  • 谢谢!非常重要的事情我不知道。我确实看过这个,但之前没有提到。
  • 我明白,但这并没有解决我的问题,我编辑了我的 xmls
  • @DoctororDrive 还有其他建议吗?
  • 也许你应该再给我们看一些代码,因为布局看起来不错。
猜你喜欢
  • 1970-01-01
  • 2020-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-15
相关资源
最近更新 更多