我想有一个活动,其中包含两个片段,其中一个列表视图(比屏幕高度可容纳更多的项目)和一个与另一个列表视图(只有几个元素)。片段A应该在片段B之上,但片段B应该只有在片段A中的列表视图滚动到结尾时才可见。 一个例子:ListView1的(片段A)含有20项(屏幕可以同时持有6项)和ListView2包含3项ListView下面ListView(与许多项目)
Initial view Scrolled down to end of ListView1
|----------------| |-----------------|
| ListView1Item1 | | ListView1Item19 |
| ListView1Item2 | | ListView1Item20 |
| ListView1Item3 | | |
| ListView1Item4 | | ListView2Item1 |
| ListView1Item5 | | ListView2Item2 |
| ListView1Item6 | | ListView2Item3 |
|----------------| |-----------------|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:id="@+id/containerOverview"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/containerKommentar"
android:layout_below="@+id/containerOverview"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"></FrameLayout>
</RelativeLayout>
我想我可以用滚动型做,但是这只能容纳一个元件。
有一点需要注意:我的两个碎片都是以编程方式创建的,因为我需要将一些(动态)参数传递给它。
我希望你能理解我的问题,并且有办法处理它。 谢谢
'但片段B只应该是可见的,如果片段A中的列表视图滚动到结尾.'不可能,除非您将片段放在片段A的页脚中的视图中,但是然后,列表视图会在这里不适合。我建议尝试将所有元素放在同一个ListView中,可能使用MergeAdapter(https://github.com/commonsguy/cwac-merge) – njzk2 2014-10-06 20:34:28
您可以使用适配器类中的项目类型getItemView()和getItemViewTypeCount()通过单个列表和单个适配器实现您想要的功能。 – zgc7009 2014-10-06 20:38:42