Question

I have an imageview that is larger than the screen size so I am using a Scrollerobject myScroller to handle the scrolling. However, I cannot get the correct current scroll position.

I have tried using the methods outlined in the developer guides for Scroller:

  • myScroller.getCurrX() and myScroller.getCurrY()
  • myScroller.getStartX() and myScroller.getStartY()

And then there is the getScrollX() and getScrollY() methods for the View class... which are the correct methods to use?

I am updating the position in the onTouchEvent under the case MotionEvent.ACTION_UP

case MotionEvent.ACTION_UP:

        //if(mScroller.isFinished()){
        mScroller.computeScrollOffset();
        mPosX = getScrollX(); // **should this be myScroller.getCurrX()?**
        mPosY = getScrollY();
        //Log.d("OnScale", "scrollPosition: [" + mPosX + ", " + mPosY + "]");
        }

But this does not seem to update the scrollPosition correctly every time. What is the correct way to get the scroll position of my imageview? To clarify, I would like the coordinates of the top left corner.

Was it helpful?

Solution

Ok, I managed to figure out that

  • getScrollX()
  • getScrollY()

is the correct way to get the scroll position of the child view. I'm still not sure why/what the difference is between this an using the Scroller.getCurrX()/getCurrY methods, but they definitely return drastically different values sometimes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top