问题描述:
在ViewPager的子VIew中, 嵌套使用SwipeRefreshLayout, 发现SwipeRefreshLayout的下拉功能时而就不能使用。
原因:
down vote
It is because there is a bug in SwipeRefreshLayout! The bug is “onRefresh doesn’t work properly if the onMeasure is not called” !
由于在SwipeRefreshLayout 没有调用onMeasure 之前, onRefresh 不能正常工作。
http://stackoverflow.com/questions/30422471/swiperefreshlayout-inside-viewpager
解决办法:
public class SwipeRefreshLoading extends SwipeRefreshLayout {
public SwipeRefreshLoading(Context context) {
super(context, null);
}
public SwipeRefreshLoading(Context context, AttributeSet attrs) {
super(context, attrs);
}
private boolean mMeasured = false;
private boolean mPreMeasureRefreshing = false;
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (!mMeasured) {
mMeasured = true;
setRefreshing(mPreMeasureRefreshing);
}
}
@Override
public void setRefreshing(boolean refreshing) {
if (mMeasured) {
super.setRefreshing(refreshing);
} else {
mPreMeasureRefreshing = refreshing;
}
}
}