Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, I think you should be aware of this: <a href="https://stackoverflow.com/questions/4490821/scrollview-inside-scrollview">ScrollView Inside ScrollView</a></p> <p>In short: <strong>using scrollviews inside scrollviews is a bad thing that breaks many optimizations.</strong></p> <p>Now, onto your question.</p> <p>I've had a similar need to what you described. I ended up implementing a custom view and its <code>onDraw</code> method. This was in part because I was drawing something not trivial and you may not have to do it.</p> <p>Anyway, I believe that your best option is:</p> <ol> <li>Implement a custom view that extends relative layout</li> <li>create the layout of this view with the top, left and "main" views that will be the scrollable components</li> <li>add a <a href="http://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html" rel="nofollow noreferrer">OnGestureListener</a> to this view and pass touch events in your activity into the custom view</li> <li>when your gesture listener detects a fling or a scroll, invoke <code>scrollBy</code> in each of the scrolling views. When you do this, if you want the top view to scroll horizontally only, pass 0 as the vertical scroll distance.</li> <li>In order to implement smooth fling movements, you need to create a <a href="http://developer.android.com/reference/android/widget/Scroller.html" rel="nofollow noreferrer">scroller</a> (in your custom view). When the gesture listener detects a fling event, set the scroller up. Then, override your custom view's <code>computeScroll()</code> method and update the scroll in each of child views. <strike>Check this <a href="http://androidcore.com/android-programming-tutorials/608-android-two-dimensional-scrollview.html" rel="nofollow noreferrer">example</a> to know how to implement it. I apologize, I will try to post a better example when possible.</strike> <strong>Check my code below... it's simpler :)</strong></li> </ol> <p><strong>Update:</strong> sample code</p> <pre><code>@Override public void computeScroll() { if (scroller.computeScrollOffset()) { if (!scrolledLastFrame) { lastX = scroller.getStartX(); lastY = scroller.getStartY(); } int dx = scroller.getCurrX() - lastX; int dy = scroller.getCurrY() - lastY; lastX = scroller.getCurrX(); lastY = scroller.getCurrY(); doScroll(dx, dy); scrolledLastFrame = true; } else { scrolledLastFrame = false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload