SwipeRefreshLayout是Google推出的一款下拉刷新的控件。
- 有时这个控件在和ListView滑动时有冲突,ListView只能往下查看,不能查看上面的数据了。如何解决这个冲突呢,现在我们就来重写SwipeRefreshLayout
/**
* 支持滑动判断的 SwipeRefreshLayout
* 写监听子控件的滑动的滑动方法
*/
public class GeneralSwipeRefreshLayout extends SwipeRefreshLayout {
private OnChildScrollUpListener childScrollListener;
public interface OnChildScrollUpListener {
boolean canChildScrollUp();
}
public GeneralSwipeRefreshLayout(Context context) {
super(context);
}
public GeneralSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* Listener that controls if scrolling up is allowed to child views or not
*/
public void setOnChildScrollUpListener(OnChildScrollUpListener listener) {
childScrollListener = listener;
}
@Override
public boolean canChildScrollUp() {
if (childScrollListener == null) {
Log.e(GeneralSwipeRefreshLayout.class.getSimpleName(), "listener is not defined!");
}
return childScrollListener != null && childScrollListener.canChildScrollUp();
}
}
- 现在我们只需要在Activity或Fragment等界面中调用SwipeRefreshLayout的setOnChildScrollUpListener();
......
swipeLayout.setOnChildScrollUpListener(new GeneralSwipeRefreshLayout.OnChildScrollUpListener() {
@Override
public boolean canChildScrollUp() {
return listView.canScrollVertically(-1);
}
});
......
感谢大家的支持