首页 > 学院 > 开发设计 > 正文

ViewPager嵌套使用SwipeRefreshLayout下拉功能不能使用

2019-11-09 18:03:50
字体:
来源:转载
供稿:网友

问题描述: 在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; } }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表