【发布时间】:2014-09-11 20:05:02
【问题描述】:
我有一个 ListView 始终启用 fastScroll 并实现 SwipeRefresh。当我向下滑动列表时,它会刷新列表。我的问题是fastScroll。如果列表的第一项可见或在其初始顶部显示,那么如果向下滚动 fastScrollThumb,它会产生 Swipe 效果而不是向下滚动。无论如何/解决方案,如果我按下 fastScrollThumb ,那么它不应该做 Swipe 刷新效果,而是它应该向下滚动作为它的自然行为。
已编辑
我的XML Layout如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/buttons_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp">
<ImageView
android:id="@+id/SubmitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/neoo_tab_selector" />
</RelativeLayout>
<ListView
android:id="@id/android:list"
style="@style/NeeoContactListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/buttons_layout"
android:layout_marginTop="10dp" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
我的 Logic for onScroll 用于启用/禁用 SwipeRefresh 是:
getListView().setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
boolean enable = false;
if(getListView() != null && getListView().getChildCount() > 0){
// check if the first item of the list is visible
boolean firstItemVisible = getListView().getFirstVisiblePosition() == 0;
// check if the top of the first item is visible
boolean topOfFirstItemVisible = getListView().getChildAt(0).getTop() == 0;
// enabling or disabling the refresh layout
enable = firstItemVisible && topOfFirstItemVisible;
}
if(enable){
enableSwipe();
}else{
disableSwipe();
}
}
});
【问题讨论】:
-
你的列表视图应该有 >
listView.setOnScrollListener(...) -
我已经在使用
listView.setOnScrollListener(...),其中m使用上面提到的onScroll方法。
标签: android android-listview fastscroll