title: Android measure view visible area
body: <p>I have been searching a lot of similar answer from here, but none can work accurately. I want to calculate the visible area of a custom view, the view can be blocked by the screen edge, or block by the edge of scroll view, let see the picture below:</p>
  
  <p><a href="https://i.stack.imgur.com/MDvcP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MDvcP.jpg" alt="enter image description here"></a></p>
  
  <p>As above, black color is my screen, red color is my custom view and scroll up a bit, I want to measure area of B.</p>
  
  <p><a href="https://i.stack.imgur.com/T0v7Z.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T0v7Z.jpg" alt="enter image description here"></a></p>
  
  <p>As above, black color is my screen, red color is my custom view, blue color is scroll view. Custom view is child of the scroll view and it is scroll up a bit. I want to measure area of B. </p>
  
  <p>1) I have tried, <code>View.getWindowVisibleDisplayFrame</code>, <code>View.getLocalVisibleRect</code>, <code>View.getGlobalVisibleRect</code>, but none of it work accurately. First glance they looks good, but when I scroll my view disappear from screen, somehow, it show me the full height and width of the view, which the view is not even displayed within the screen.</p>
  
  <p>2) I tried <code>View.getLocationOnScreen()</code> and <code>getLocationInWindow()</code> to calculate the offset manually, get XY coordination and plus/minus the view's (and screen) height and width, but found it not easy too, because the top of screen always have extra menu bar or etc, and will mess out with the result. </p>
  
  <p>3) Although this is not likely in my situation, I want to know, if there is a absolute layout on top of my view and partially block it, can I still find out the area? (both layout are in same activity)</p>
  
  <p>My question is, is there any easy and accurate way to calculate the area I want? </p>