文档开发者中心
我的

SwipeRefreshLayout控件刷新后快速点击无效求助

奇怪的问题,测试手机是荣耀9,Android版本7.0,support库使用25.3.1版本时,一切正常;
但是使用26.1.0版本时,SwipeRefreshLayout控件刷新后快速点击无效,需要等一段时间才能点击栏目。



这个问题只在荣耀9和nova手机上发现了,其他手机正常。


这是响应处代码
  1. srl_refresh_tool.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  2.             @Override
  3.             public void onRefresh() {
  4.                     srl_refresh_tool.postDelayed(new Runnable() {
  5.                         @Override
  6.                         public void run() {
  7.                             srl_refresh_tool.setRefreshing(false);
  8.                         }
  9.                     }, 500);
  10.             }
  11.         });
复制代码
已经解决:
  1. public class MyRecyclerView extends RecyclerView {
  2.     public MyRecyclerView(Context context) {
  3.         super(context);
  4.     }
  5.     public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
  6.         super(context, attrs);
  7.     }
  8.     public MyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
  9.         super(context, attrs, defStyle);
  10.     }
  11.     @Override
  12.     public boolean onInterceptTouchEvent(MotionEvent event) {
  13.         boolean requestCancelDisallowInterceptTouchEvent = getScrollState() == SCROLL_STATE_SETTLING;
  14.         boolean consumed = super.onInterceptTouchEvent(event);
  15.         final int action = event.getActionMasked();
  16.         switch (action) {
  17.             case MotionEvent.ACTION_DOWN:
  18.                 if( requestCancelDisallowInterceptTouchEvent ){
  19.                     getParent().requestDisallowInterceptTouchEvent(false);
  20.                     // only if it touched the top or the bottom. Thanks to @Sergey's answer.
  21.                     if (!canScrollVertically(-1) || !canScrollVertically(1)) {
  22.                         // stop scroll to enable child view to get the touch event
  23.                         stopScroll();
  24.                         // do not consume the event
  25.                         return false;
  26.                     }
  27.                 }
  28.                 break;
  29.         }
  30.         return consumed;
  31.     }
  32. }
复制代码

点赞
收藏
回复
分享
举报
浏览1450 编辑于2017-11-29 03:07未知归属地
全部评论
最多点赞
最新发布
最早发布
暂无评论
暂无评论
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。