您的位置:首页 > 其它

解决SwipeRefreshLayout多重嵌套产生滑动冲突

2015-08-13 12:25 375 查看
   在最近的项目中由于用到了SwipeRefreshLayout和RecycleView带有头部,导致了滑动冲突。SwipeRefreshLayout设计时判断滑动子控件滑动事件时没有考虑这种嵌套的情款。所以现在贴出这个代码可以解决和我一样遇到这个问题的同学。 希望有点帮助。

public class RecycleRefreshLayout extends SwipeRefreshLayout {

private static final String TAG = RecycleRefreshLayout.class.getCanonicalName();

public RecycleRefreshLayout(Context context) {
super(context);
}

public RecycleRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public boolean canChildScrollUp() {
return canChildScrollUp(this);
}

public boolean canChildScrollUp(ViewGroup v) {
for (int i = 0; i < v.getChildCount(); i++) {
View temp = v.getChildAt(i);
if (temp instanceof RecyclerView) {
if (canRecycleViewScroll((RecyclerView) temp)) return true;
} else if (temp instanceof AbsListView){
if (ViewCompat.canScrollVertically(temp, -1))return true;
}else if (temp instanceof ViewGroup) {
if (canChildScrollUp((ViewGroup) temp)) return true;
} else if (ViewCompat.canScrollVertically(temp, -1)) return true;
}
return false;
}

public boolean canRecycleViewScroll(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
return ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition() != 0;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: