【问题标题】:Show multi ListView in one screen在一个屏幕上显示多个 ListView
【发布时间】:2013-05-02 06:16:46
【问题描述】:

我有 2 个 ListView,每个都从网站数据库中获取信息.... 一切都很好,但我想要的是显示第一个列表视图,然后在它下面显示第二个列表视图而不设置固定高度..就像用户应该滚动到第一个列表视图的末尾,然后显示第二个列表视图而不显示滚动条。这是我所做的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/firstlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ListView>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <ListView
        android:id="@+id/secondlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         >
     </ListView>
    </RelativeLayout>

</LinearLayout>

但即使我继续滚动屏幕也不会同时显示,只有一个列表视图(第一个)显示...除非我给它们固定高度,例如 android:layout_height="180dp" 任何想法?

【问题讨论】:

    标签: android listview


    【解决方案1】:

    我以前也有同样的问题。以下是四种解决方案:

    1.为每个列表视图提供android:layout_weight = "1",以便他们可以将屏幕减半。

    2.把它们放在一个tabview中。

    3.将两个列表合并为一个列表视图。

    4.使用ExpandableListView

    【讨论】:

    • 我认为 2 号是更好的解决方案。只要我不能合并它们或将它们放入 ExpandableListView 因为每个人都有自己的信息..
    【解决方案2】:

    你为什么不使用ExpandableListView

    Example 1

    Example 2

    Example 3

    【讨论】:

    • 没问题,它会处理这个的。
    • 你说得对,非常感谢,但我想我会关注 tabview,因为我认为它可以提供一个不错的界面..
    【解决方案3】:

    你能试试这个吗?

    <?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="@+id/listView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="#C0C0C0" >
    </LinearLayout>
    
    <ListView
        android:id="@+id/listView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>
    

    【讨论】:

    • 好吧,我仍然需要滚动它们,两个列表视图从一半显示在同一个屏幕中..
    猜你喜欢
    • 2019-01-25
    • 2014-02-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多