title: Android - HorizontalScrollView - get view in focus (or index of it)
body: <p>I have a <code>HorizontalScrollView</code> containing a <code>LinearLayout</code>, which in turn contains a couple of <code>FrameLayout</code>s. Each <code>FrameLayout</code> contains the layout of a <code>Fragment</code>. Now I'm trying to get the view, i.e. <code>FrameLayout</code>, which is currently visible or in focus within the <code>HorizontalScrollView</code>. As soon as I have the view in focus I could get it's index within the <code>LinearLayout</code>.</p>
  
  <p>I've tried the following, but nothing works:</p>
  
  <ul>
  <li>HorizontalScrollView.findFocus() - returns null</li>
  <li>LinearLayout.findFocus() - returns null</li>
  <li>LinearLayout.getFocusedChild() - returns null</li>
  <li>FrameLayout.hasFocus() - returns false for all <code>FrameLayout</code>s</li>
  </ul>
  
  <p>I could also try to figure out which child of the <code>LinearLayout</code> has focus, by doing calculations based on current X-position of each child. However, calling <code>getX()</code> on each child always returns "0.0".</p>
  
  <p>Does anyone have an idea how to get the view in focus (or even better it's index within the <code>LinearLayout</code>)?</p>