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

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

问题描述

我想创建一个网页,有3个表和3头,但我不希望独立滚动他们,我希望整个页面滚动。有谁知道我能做到这一点?

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

 头
smlheader
名单
smlheader
名单
smlheader
名单
 

通过这个code我试着去实现它,但它并不好。

 < XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android

< TableLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@色/白>

   <包括布局=@布局/头/>
   <包括布局=@布局/ redcell/>

   <的TableRow

       机器人:ID =@ + ID / tableRow1
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =60dp>


      <的TextView

        机器人:ID =@ + ID / fixtures_text
        机器人:layout_width =match_parent
        机器人:layout_height =60dp

        机器人:重力=中心
        机器人:文本=@字符串/联盟
        机器人:文字颜色=@色/白
        机器人:TEXTSIZE =25dp
        机器人:TEXTSTYLE =黑体/>




   < /的TableRow>

   <包括布局=@布局/ redcell/>

   <的TableRow
       机器人:ID =@ + ID / tableRow2
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =60dp>


      <的TextView

        机器人:ID =@ + ID / results_text
        机器人:layout_width =match_parent
        机器人:layout_height =60dp

        机器人:重力=中心
        机器人:文本=@字符串/联盟
        机器人:文字颜色=@色/白
        机器人:TEXTSIZE =25dp
        机器人:TEXTSTYLE =黑体/>

   < /的TableRow>

    <包括布局=@布局/ redcell/>


    <的ListView
    机器人:ID =@机器人:ID /列表
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
   />

< / TableLayout>
<滚动型/>
 

解决方案

我会尝试CommonsWare MergeAdapter 为指向拉杰什。这听起来像正是你需要的。

这将需要多个视图(包括列表视图),并把它们放在一起,然后设置合并适配器列表视图和preSTO,你必须在一个列表视图几个

从文档报价吧:

MergeAdapter接受适配器和观点,presents他们作为一个连续的整体,任何的ListView被倒入混合。在这里你有多个数据源,或者这是很好的情况下,如果你有一把普通视图混合在数据列表等。

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

修改

1)下载从该.jar这里
2)下载该.jar的 CWAC SackOfViewsAdapter 作为MergeAdapter需要它。照片 2)在项目中创建名为库(在同一水平上的SRC与放一个目录;水库)
3)把两个.jar文件的文件夹中(Eclipse应当自动采取从那里远东西将其设置为包含在构建)
4)每次使用的说明MergeAdapter从第一个环节在我原先的响应。

伪code例如:

  myMergeAdapter =新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

添加你的头它是一个完整的布局:

 查看标题= getLayoutInflater.inflate(R.layout.red_cell);
myMergeAdapter.addView(头);
 

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/>

解决方案

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.

Quoting from the docs for it:

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.

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

EDIT

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.

Pseudo-code example:

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);

EDIT 2

Adding your header which is a complete layout:

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

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

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