不独立滚动的Android多个列表视图 [英] Android multiple list views that don't scroll independently

查看:25
本文介绍了不独立滚动的Android多个列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个包含 3 个列表和 3 个标题的页面,但我不想单独滚动它们,我希望滚动整个页面.有谁知道我是如何做到这一点的?

I want to create a page that has 3 lists and 3 headers but I don't want to scroll them independently, I want the whole page to scroll. Does anyone know how I could achieve this?

基本上我希望它看起来像这样:

Essentially I want it to look like this:

header
smlheader
list
smlheader
list
smlheader
list

使用此代码,我已尝试实现它,但效果不佳.

With this code I've tried to achieve it but it's not that good.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white">

   <include layout="@layout/header" />
   <include layout="@layout/redcell" />

   <TableRow

       android:id="@+id/tableRow1"
       android:layout_width="wrap_content"
       android:layout_height="60dp" >


      <TextView

        android:id="@+id/fixtures_text"
        android:layout_width="match_parent"
        android:layout_height="60dp"

        android:gravity="center"
        android:text="@string/leagues"
        android:textColor="@color/white"
        android:textSize="25dp"
        android:textStyle="bold"/>




   </TableRow>

   <include layout="@layout/redcell" />

   <TableRow
       android:id="@+id/tableRow2"
       android:layout_width="wrap_content"
       android:layout_height="60dp" >


      <TextView

        android:id="@+id/results_text"
        android:layout_width="match_parent"
        android:layout_height="60dp"

        android:gravity="center"
        android:text="@string/leagues"
        android:textColor="@color/white"
        android:textSize="25dp"
        android:textStyle="bold"/>

   </TableRow>

    <include layout="@layout/redcell" />


    <ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   />

</TableLayout>
<ScrollView/>

推荐答案

我会尝试 CommonsWare MergeAdapter 正如 Rajesh 所指出的那样.这听起来正是您所需要的.

I would try CommonsWare MergeAdapter as pointed to by Rajesh. It sounds like exactly what you need.

它将采用多个视图(包括列表视图)并将它们放在一起,然后您将合并适配器设置为列表视图并快速,您将多个列表视图合二为一.

It will take multiple views (including listviews) and put them together, then you set the merge adapter to a listview and presto, you have several listviews in one.

从文档中引用它:

MergeAdapter 接受适配器和视图的混合,并将它们作为一个连续的整体呈现给它注入的任何 ListView.这适用于您有多个数据源的情况,或者如果您有少量普通视图与数据列表混合等情况.

MergeAdapter accepts a mix of Adapters and Views and presents them as one contiguous whole to whatever ListView it is poured into. This is good for cases where you have multiple data sources, or if you have a handful of ordinary Views to mix in with lists of data, or the like.

只需创建一个 MergeAdapter 并调用 addAdapter()、addView() 或 addViews()(后者接受一个 List),然后将您的适配器附加到 ListView.

Simply create a MergeAdapter and call addAdapter(), addView(), or addViews() (latter accepting a List), then attach your adapter to the ListView.

编辑

1) 从 此处
2) 下载 CWAC SackOfViewsAdapter 的 .jar因为 MergeAdapter 需要它.
2) 在您的项目中创建一个名为libs"的目录(与 src & res 处于同一级别)
3) 将两个 .jar 文件放在该文件夹中(Eclipse 应该自动从那里获取内容,直到将其设置为包含在构建中)
4) 按照我原始回复中第一个链接中的说明使用 MergeAdapter.

1) Download the .jar from here
2) Download the .jar for CWAC SackOfViewsAdapter as the MergeAdapter requires it.
2) Create a directory in your project called "libs" (on the same level as src & res)
3) place both of the .jar files in that folder (Eclipse should automatically take things from there as far as setting it up to be included in the build)
4) Use the MergeAdapter per the instructions from the first link in my original response.

伪代码示例:

myMergeAdapter = new MergeAdapter();
myMergeAdapter.addView(HeaderView);
myMergeAdapter.addView(SmallHeaderView1);
myMergeAdapter.addAdapter(listAdapter1);
myMergeAdapter.addView(SmallHeaderView2);
myMergeAdapter.addAdapter(listAdapter2);
myMergeAdapter.addView(SmallHeaderView3);
myMergeAdapter.addAdapter(listAdapter3);

setListAdapter(myMergeAdapter);

编辑 2

添加您的标题,这是一个完整的布局:

Adding your header which is a complete layout:

View Header = getLayoutInflater.inflate(R.layout.red_cell);
myMergeAdapter.addView(Header);

这篇关于不独立滚动的Android多个列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆