在我用swiperefresh嵌套头布局为viewpager的listview时候,刷新的逻辑是清空listview填充布局的集合,viewpager的集合,然后重新请求数据请求完以后布局就乱套了,我重写了listview的onscrolllistener中的
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
boolean enable = false;
if(listView != null && listView.getChildCount() > 0){
// check if the first item of the list is visible
boolean firstItemVisible = listView.getFirstVisiblePosition() == 0;
// check if the top of the first item is visible
boolean topOfFirstItemVisible = listView.getChildAt(0).getTop() == 0;
// enabling or disabling the refresh layout
enable = firstItemVisible && topOfFirstItemVisible;
}
swipe.setEnabled(enable);
};
重写了这个为了解决listview和swiperefreshlayout的冲突。我也重写了swiperefresh'layout的
@Override
public boolean canChildScrollUp() {
if (view != null && view instanceof AbsListView) {
final AbsListView absListView = (AbsListView) view;
return absListView.getChildCount() > 0
&& (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
.getTop() < absListView.getPaddingTop());
}
return super.canChildScrollUp();
}
可是刷新完换是有问题
布局上面的viewpager乱套了
viewpager不在顶部啊