Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All right I figured it out by myself.</p> <p>First I had to extend the ScrollView class and added an interface OnScrollViewListener.</p> <pre><code>public class MyScrollView extends ScrollView { private OnScrollViewListener mListener; public MyScrollView(Context c, AttributeSet attrs) { super(c, attrs); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (mListener != null) { mListener.onScrollChanged((OnScrollViewListener) this); } } public void setOnScrollViewListener(OnScrollViewListener listener) { mListener = listener; } public static interface OnScrollViewListener { public void onScrollChanged(OnScrollViewListener listener); } } </code></pre> <p>Next in my Activity I inserted a member mScrollDistance that indicates the amount of pixels the user scrolls.</p> <pre><code>public class ScrollActivity extends Activity { private int mScrollDistance; @Override protected void OnCreate(...) { ... final MyScrollView myScrollView = (MyScrollView) findViewById(R.id.scroll_view); myScrollView.setOnScrollViewListener(new MyScrollView.OnScrollViewListener() { public void onScrollChanged(OnScrollViewListener listener) { mScrollDistance = listener.getScrollY(); } } // making an drag and drop in an view that is inside the MyScrollView final LinearLayout myLayout = (LinearLayout)findViewById(R.id.linear_layout); myLayout.setOnDragListener(new View.OnDragListener() { public boolean onDrag (View v, DragEvent event) { int action = event.getAction(); switch(action) { case DragEvent.ACTION_DRAG_STARTED: { } case DragEvent.ACTION_DRAG_LOCATION: { int y = Math.round(event.getY()); int translatedY = y - mScrollDistance; int threshold = 50; // make a scrolling up due the y has passed the threshold if (translatedY &lt; threshold) { // make a scroll up by 30 px myScrollView.scrollBy(0, -30); } // make a autoscrolling down due y has passed the 500 px border if (translatedY + threshold &gt; 500) { // make a scroll down by 30 px myScrollView.scrollBy(0, 30); } // listen for more actions here // ... } } } } </code></pre> <p>Now, mScrollDistance gets always a new value and the drag location will be translated to the view location. I tested this and it works on layouts/views that are bigger than the screen size.</p> <p>Hope that helps.</p>
    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