Pan-able Layout (needs a little fix to work)

68 views Asked by At

I am trying to make a panable linear layout. Here is a part of the code from best answer of How can I make my layout scroll both horizontally and vertically? tread. Everything works on first touch and drag cycle, but on second drag, layout position resetting to first position. So overall position does not changing. The reason is intercepting ACTION_DOWN event by scrollView. How to fix it?

 @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                lastX = event.getX();
                lastY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = event.getX();
                curY = event.getY();
                vScroll.scrollBy((int) (lastX - curX), (int) (lastY - curY));
                hScroll.scrollBy((int) (lastX - curX), (int) (lastY - curY));
                lastX = curX;
                lastY = curY;
                break;
            case MotionEvent.ACTION_UP:
                curX = event.getX();
                curY = event.getY();
                vScroll.scrollBy((int) (lastX - curX), (int) (lastY - curY));
                hScroll.scrollBy((int) (lastX - curX), (int) (lastY - curY));
                break;
        }

        return true;
    }

Differently from original, I just changed variable names and moved declaration to top of code.

(Sorry if any language mistakes, English is not my native one)

0

There are 0 answers