[英]two listViews in one activity
I have two list views.我有两个列表视图。
The problem I have is that screen scrolls until smaller(height) listview reaches the bottom.我遇到的问题是屏幕滚动直到更小(高度)的列表视图到达底部。
How can I expand the containing view so that I can scroll to the bottom of longer listView?如何展开包含视图以便我可以滚动到更长的 listView 的底部?
I overloaded onScroll to scroll both list at the same time.我重载 onScroll 以同时滚动两个列表。
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
super.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
if (view.getChildAt(0) != null) {
if (view.equals(m_lv1) ){
m_lv2.setSelectionFromTop(view.getFirstVisiblePosition(),
view.getChildAt(0).getTop());
} else if (view.equals(m_lv2) ){
m_lv1.setSelectionFromTop(view.getFirstVisiblePosition(),
view.getChildAt(0).getTop());
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list_view_left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1" >
</ListView>
<ListView
android:id="@+id/list_view_right"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
you have to set the height of the listview...like.你必须设置列表视图的高度......就像。
<ListView
android:id="@+id/list_view_left"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:scrollbars="none"
android:layout_weight="1" >
</ListView>
<ListView
android:id="@+id/list_view_right"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_weight="1" >
</ListView>
Use below XML code instead of your code.使用下面的 XML 代码而不是您的代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/list_view_left"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</ListView>
<ListView
android:id="@+id/list_view_right"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.