1、getScrollX()
原点(0,0)为view左上角的坐标点。实际移动的为view的内容而并非view本身,返回值为view的内容相对于view本身的水平或者垂直方向的偏移量。
getScrollX():原点X坐标减去view内容移动后 内容左上角X坐标(左移正,右移负)
getScrollY():原点Y坐标减去view内容移动后 内容左上角Y坐标 (上移正,下移负)
2、scrollTo()、scrollBy()
scrollTo()源码
/**
* Set the scrolled position of your view. This will cause a call to
* {@link #onScrollChanged(int, int, int, int)} and the view will be
* invalidated.
* @param x the x position to scroll to
* @param y the y position to scroll to
*/
public void scrollTo(int x, int y) {
if (mScrollX != x || mScrollY != y) {
int oldX = mScrollX;
int oldY = mScrollY;
mScrollX = x;
mScrollY = y;
invalidateParentCaches();