Toolbar滑动隐藏与IRecyclerView冲突

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冲突)