title: Hide View Propotional to RecyclerView Scrolling
body: <p>In my android application I have a recyclerview and LinearLayout. LinearLayout lies on the top and recyclerview lies down to the linearlayout. what my requirement is when recyclerview starts scrolls the last item, the linearlayout should start hide in propotion to scroll amount.</p>
  
  <p>I have done a little and it works. but it is not proportional to the scroll amount. here is my code</p>
  
  <p><strong>ScrollListener</strong></p>
  
  <pre><code>public class MyScrollListener extends OnScrollListener {
  
      private LinearLayoutManager mLayoutManager;
  
      public MyScrollListener(LinearLayoutManager manager) {
          this.mLayoutManager = manager;
      }
  
      @Override
      public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  
          int visibleItemCount = mLayoutManager.getChildCount();
          int totalItemCount = mLayoutManager.getItemCount();
          int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
  
          if (visibleItemCount + firstVisibleItem &gt;= totalItemCount) {
              scrollTheShit(dy * -1, ((View) recyclerView.getChildAt(visibleItemCount - 1)).getWidth());
          }
      }
  
      public void scrollTheShit(int dy, int widthOfLastChild) {}
  
  
  }
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      RecyclerView recyclerView;
      LinearLayout linearLayout;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          linearLayout = (LinearLayout) findViewById(R.id.container);
          recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
          recyclerView.setHasFixedSize(true);
          final LinearLayoutManager mgr = new LinearLayoutManager(this);
          recyclerView.setLayoutManager(mgr);
          recyclerView.setAdapter(new RecyclerAdapter());
  
  
          recyclerView.addOnScrollListener(new MyScrollListener(mgr) {
  
              @Override
              public void scrollTheShit(int dy, int widthOfLastChild) {
  
                  linearLayout.setY(linearLayout.getY() + dy );
              }
          });
      }
  
  
      private class RecyclerAdapter extends Adapter&lt;RecyclerAdapter.ViewHolder&gt; {
  
  
          @Override
          public int getItemCount() {
              return 10;
          }
  
          @Override
          public void onBindViewHolder(ViewHolder viewHolder,
                                       int position) {
          }
  
          @Override
          public ViewHolder onCreateViewHolder(ViewGroup parent, int position) {
              View v = LayoutInflater.from(MainActivity.this)
                      .inflate(R.layout.child, parent, false);
              ViewHolder holder = new ViewHolder(v);
              return holder;
          }
  
          public class ViewHolder extends RecyclerView.ViewHolder {
  
              public ViewHolder(View arg0) {
                  super(arg0);
              }
  
          }
      }
  
  }
  </code></pre>
  
  <p>I have to hide the top section when the below RecyclerView scrolls
  <a href="https://i.stack.imgur.com/gFRZX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gFRZX.png" alt="enter image description here"></a></p>
  
  <p>how do I correct this ? anyone please help me</p>