if (recyclerView != null) { if (mToolbar != null) { float offset = mToolbar.getTranslationY() - dy; if (offset <= 0 && offset >= -(mToolbar.getHeight())) { mToolbar.setTranslationY(mToolbar.getTranslationY() - dy); FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) mCoordinatorLayout.getLayoutParams(); params1.setMargins(0, params1.topMargin - dy, 0, 0); if (RecyclerView.SCROLL_STATE_IDLE == newState) { if(mToolbar != null) { if (Math.abs(mToolbar.getTranslationY()) <= mToolbar.getHeight() / 2) { ObjectAnimator animator = ObjectAnimator.ofFloat(mToolbar, View.TRANSLATION_Y, mToolbar.getTranslationY(), 0); animator.setDuration(300); animator.start(); mCoordinatorLayout.startAnimation(animation); } else { ObjectAnimator animator = ObjectAnimator.ofFloat(mToolbar, View.TRANSLATION_Y, mToolbar.getTranslationY(), -mToolbarHeight); animator.setDuration(300); animator.start();