title: Finding top offset of first visible item in a RecyclerView
body: <p>I have a RecyclerView + LinearLayoutManger which is using an adapter that holds chat messages. I limit the number of chat messages to the most 100 recent. This issue is that when I remove the older chats, the scroll position of the chats in the recyclerview changes because index 0 was removed. I began writing the code below:</p>
  
  <pre><code>int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
  View v = layoutManager.getChildAt(firstVisiblePosition);
  if (firstVisiblePosition &gt; 0 &amp;&amp; v != null) {
      int offsetTop = //need to get the view offset here;
      chatAdapter.notifyDataSetChanged();
  
      if (firstVisiblePosition - 1 &gt;= 0 &amp;&amp; chatAdapter.getItemCount() &gt; 0) {
          layoutManager.scrollToPositionWithOffset(firstVisiblePosition - 1, offsetTop);
      }
  }
  </code></pre>
  
  <p>I thought it would be easy to get the visible offset of the first visible item position. Ex. if the first visible view is 300dp but only the last 200dp is visible, I would like to get the 100 offset.</p>
  
  <p>This way I could use scrollToPositionWithOffset(firstVisiblePosition - 1, offsetTop).</p>
  
  <p>Am I missing something here? This seems like it would be an easy problem to figure out, but I haven't seen any methods that would support this.</p>