title: Determine if a view is on screen - Android
body: <p>I'm a little bit stuck with this one - first and foremost, the following link has been useful however I've come up with a bit of an issue with visibility:</p>
  
  <p>The link: <a href="https://stackoverflow.com/questions/4628800/android-how-to-check-if-a-view-inside-of-scrollview-is-visible" title="Check view visbilitiy">Check view visibility</a></p>
  
  <p>I have a scroll view (parent) and a number of sub-views (<code>LinearLayout</code> -> <code>TableLayout</code>) etc. There are a number of items I set to <code>View.GONE</code> within the XML (<code>android:visibility="gone"</code>).</p>
  
  <p>I have some simple code to determine whether it is visible or not using <code>getVisibility()</code> however when I set the item to <code>View.VISIBLE</code> and try to immediately <code>getDrawingRect()</code> I get a Rect with zeros across the board. Any further click gets the correct coordinates.</p>
  
  <p>Now this could be because the view has never been drawn (as defined in the XML) causing it to return no coordinates however I do set <code>View.VISIBLE</code> before trying to determine screen visibility. Could it be that I need to get some kind of callback from say the onDraw()? or perhaps set the view visibility of hidden items within code. A bit annoying ;(</p>
  
  <p>Some code:</p>
  
  <pre><code>Rect scrollBounds = new Rect();
  scroll.getHitRect(scrollBounds);
  
  Rect viewBounds = new Rect();
  
  if (view.getVisibility() == View.GONE) {
      view.setVisibility(View.VISBLE)
  
  
      viewBounds.getDrawingRect(viewBounds);
      if (!Rect.intersects(scrollBounds, viewBounds) {
          // do somthing
      } 
  }
  </code></pre>
  
  <p>Layouts area as follows:</p>
  
  <ul>
  <li><code>ScrollView</code>
  
  <ul>
  <li><code>LinearLayout</code>
  
  <ul>
  <li><code>TableLayout</code>
  
  <ul>
  <li><code>Button</code></li>
  <li><code>HiddenView</code></li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Of course, it's highly likely I'm going about this the wrong way altogether - basically I just want to make sure that the scrollview positions itself so the view that has become visible can be seen in it's entirety.</p>
  
  <p>If any other information is required, let me know!</p>