天天看点

解决sswiperefreshlayout与listView滑动冲突的问题

listView.setOnScrollListener(new AbsListView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(AbsListView absListView, int i) {
        Log.e("i", i + "");
    }

    @Override
    public void onScroll(AbsListView absListView, int i, int i1, int i2) {
        View firstView = absListView.getChildAt(i);

        // 当firstVisibleItem是第0位。如果firstView==null说明列表为空,需要刷新;或者top==0说明已经到达列表顶部, 也需要刷新
        if (i == 0 && (firstView == null || firstView.getTop() == 0)) {
            swipeRefreshLayout.setEnabled(true);
        } else {
            swipeRefreshLayout.setEnabled(false);
        }
    }
});