首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Listview下的listview android

Listview下的listview android
EN

Stack Overflow用户
提问于 2011-09-27 19:03:47
回答 3查看 2.2K关注 0票数 2

我想有一个包含一些内容的列表视图。在它下面,当你滚动到列表视图的按钮时,会显示一个新的标题,后面跟着一个新的列表视图。这是可能的吗?

//编辑这两个listview需要有不同的布局xml。

我试图将第二个列表视图放在第一个列表视图的脚视图中。但是第二个listview太小了。

这是我的布局

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">

        <LinearLayout android:id="@+id/header"
            android:background="@drawable/app_topbar" android:layout_width="fill_parent"
            android:orientation="horizontal" android:layout_height="wrap_content"
            android:layout_alignParentTop="true">

            <TextView android:text="@string/headline_notused"
                android:gravity="center" android:textSize="24sp" android:textStyle="bold"
                android:textColor="@color/txtcolor" android:layout_width="fill_parent"
                android:layout_height="fill_parent"></TextView>

        </LinearLayout>

        <ProgressBar android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_below="@+id/header"
            android:visibility="gone" style="?android:attr/progressBarStyleHorizontal"
            android:id="@+id/progressbarHorizontal" />

        <ListView android:id="@+id/notUsedList" android:divider="@android:color/transparent"
            android:dividerHeight="5dip" android:layout_height="wrap_content"
            android:layout_marginBottom="5dip" android:layout_width="fill_parent"
            android:layout_weight="1" 
            android:layout_below="@+id/progressbarHorizontal"></ListView>

        <LinearLayout android:orientation="vertical"
            android:layout_below="@+id/notUsedList" android:background="@drawable/app_background"
            android:layout_marginBottom="55dip" android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <LinearLayout android:id="@+id/myUsedHeader"
                android:background="@drawable/app_topbar" android:layout_marginTop="10dip"
                android:layout_width="fill_parent" android:orientation="horizontal"
                android:layout_height="wrap_content" android:layout_alignParentTop="true">

                <TextView android:text="@string/headline_used" android:gravity="center"
                    android:textSize="24sp" android:textStyle="bold" android:textColor="@color/txtcolor"
                    android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView>

            </LinearLayout>

            <ListView android:id="@+id/usedList"
                android:divider="@android:color/transparent" android:dividerHeight="5dip"
                android:layout_height="fill_parent" android:layout_width="fill_parent"></ListView>

        </LinearLayout>
</RelativeLayout>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-09-27 19:23:55

你的意思是列表视图有不同的部分,每个部分都有一个标题。尝试此链接Jeff sharkey adapter

票数 2
EN

Stack Overflow用户

发布于 2011-09-27 19:13:27

当你到达列表视图的最后一项时,你应该检测到。

然后,您可以更改适配器、更改活动或其他合适的方式来显示新的ListView:

实现一个OnScrollListener,设置你的ListViewonScrollListener,然后你就可以正确地处理事情了。

例如:

代码语言:javascript
复制
// Initialization stuff.
yourListView.setOnScrollListener(this);

// ... ... ...

@Override
public void onScroll(AbsListView lw, final int firstVisibleItem,
                 final int visibleItemCount, final int totalItemCount) {

    switch(lw.getId()) {
        case android.R.id.list:     

            final int lastItem = firstVisibleItem + visibleItemCount;
            if(lastItem == totalItemCount) {
                // Last item is fully visible. You will then need to start a New activity, maybe... Or change the layout.. I don't know!
            }
    }
}
票数 1
EN

Stack Overflow用户

发布于 2011-09-27 19:15:14

是的,这是可能的。你可以在LinearLayout中定义一个列表视图,在另一个linearlayout中定义另一个列表视图,并将这两个列表视图都放在父linearlayout中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7568056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档