美文网首页
Toolbar滑动隐藏与IRecyclerView冲突

Toolbar滑动隐藏与IRecyclerView冲突

作者: 风怜目 | 来源:发表于2016-09-17 18:18 被阅读786次

    1、给Appbar添加监听

            appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
                @Override
                public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                    if (!AppBarUtils.isAppBarLayoutOpen(verticalOffset) && !AppBarUtils.isAppBarLayoutClose(appBarLayout,
                            verticalOffset)) {
                        mRecyclerView.setEnabled(false);
                    } else {
                        mRecyclerView.setEnabled(true);
                    }
                }
            });
    

    2、RecyclerView的mLastTouchY计算错误,会出现画面跳动的现象

      @Override
        public boolean onTouchEvent(MotionEvent e) {
            final int action = MotionEventCompat.getActionMasked(e);
            switch (action) {
                case MotionEvent.ACTION_DOWN: {
    
                }
                break;
    
                case MotionEvent.ACTION_MOVE: {
                   if (mStatus == STATUS_SWIPING_TO_REFRESH || mStatus == STATUS_RELEASE_TO_REFRESH) {
                     setLastTouchY(mLastTouchY);
                     return true;
               }            
                }
                break;
            }
            return super.onTouchEvent(e);
        }
    
        private void setLastTouchY(int lastY) {
            try {
                Field field = RecyclerView.class.getDeclaredField("mLastTouchY");
                field.setAccessible(true);
                field.setInt(this, lastY);
                Log.i("TEST", "mLastTouchY: " + lastY);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
    

    相关文章

      网友评论

          本文标题:Toolbar滑动隐藏与IRecyclerView冲突

          本文链接:https://www.haomeiwen.com/subject/mlkwettx.html