title: Layout Jitter when Toolbar hides while scrolling RecyclerView
body: <p><img src="https://i.stack.imgur.com/LQJrr.gif" alt="enter image description here"></p>
  
  <p>Hi , I have a layout with Toolbar, PageSlidingTab and ViewPager. Inside ViewPager there is a fragment with RecyclerView. I want to hide the Toolbar as i scroll the RecyclerView. I have achieved it by adding the following code : </p>
  
  <pre><code> toolbar  = ((MyActivity)getActivity()).getToolbar();
  
      mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
          int toolbarMarginOffset = 0;
  
          private int dp(int inPixels){
              return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, inPixels, getActivity().getResources().getDisplayMetrics());
          }
  
  
  
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
              super.onScrollStateChanged(recyclerView, newState);
  
  
          }
  
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);
              toolbarMarginOffset += dy;
              if(toolbarMarginOffset&gt;dp(56)){
  
                  toolbarMarginOffset = dp(56);
  
              }
  
              if(toolbarMarginOffset&lt;0){
  
                  toolbarMarginOffset = 0;
  
              }
  
  
              ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)toolbar.getLayoutParams();
  
              params.topMargin = -1*toolbarMarginOffset;
  
              toolbar.setLayoutParams(params);
  
  
          }
      });
  </code></pre>
  
  <p>It works fine as expected but while scrolling there is a flicker when the toolbar is hiding (As shown in image). I know its happening because of Layout resize. How can i fix this issue? Please suggest a good solution to this.</p>