解决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; } }
相关文章推荐
- Android事件总线框架Otto使用
- js事件重复绑定问题
- 借助Net-Speeder对服务器进行优化
- MyEclipse web项目导入Eclipse,详细说明
- js实现文本框宽度自适应文本宽度的方法
- 线程间操作无效: 从不是创建控件“textBox2”的线程访问它
- CSS中 @media screen 和@media only screen 和@media 的不同
- 添加第三方库出现library not found for - "解决办法
- mysql多实例(多个配置文件方式)
- There are no devices installed for the specified ADAPTORNAME
- cheat engine lua
- fibonacci(n<=45)
- 一个phonegap门外汉的phonegap初体验
- 一个phonegap门外汉的phonegap初体验
- mysql多实例
- 最近ubuntu 14.04 cpu高入住故障排除
- JavaFX学习之路:详细解释JavaFX架构和框架
- 迅雷API:实现文件下载
- leetcode 119: Pastcal's Triangle II
- hibernate中session的get()、load()方法比较