我想有一个包含一些内容的列表视图。在它下面,当你滚动到列表视图的按钮时,会显示一个新的标题,后面跟着一个新的列表视图。这是可能的吗?
//编辑这两个listview需要有不同的布局xml。
我试图将第二个列表视图放在第一个列表视图的脚视图中。但是第二个listview太小了。
这是我的布局
<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>发布于 2011-09-27 19:23:55
你的意思是列表视图有不同的部分,每个部分都有一个标题。尝试此链接Jeff sharkey adapter
发布于 2011-09-27 19:13:27
当你到达列表视图的最后一项时,你应该检测到。
然后,您可以更改适配器、更改活动或其他合适的方式来显示新的ListView:
实现一个OnScrollListener,设置你的ListView的onScrollListener,然后你就可以正确地处理事情了。
例如:
// 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!
}
}
}发布于 2011-09-27 19:15:14
是的,这是可能的。你可以在LinearLayout中定义一个列表视图,在另一个linearlayout中定义另一个列表视图,并将这两个列表视图都放在父linearlayout中。
https://stackoverflow.com/questions/7568056
复制相似问题