先看看Google的官方文档的解释
public void scrollBy (int x, int y)
Added in
API level 1
Move the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int)
and the view will be invalidated.
Parameters
x | the amount of pixels to scroll by horizontally |
---|---|
y | the amount of pixels to scroll by vertically |
public void scrollTo (int x, int y)
Added in
API level 1
Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int)
and the view will be invalidated.
Parameters
x | the x position to scroll to |
---|---|
y | the y position to scroll to |
解释:
scrollBy(int x,int y)意思就是将view移动x和y那么远的距离;而scrollTo(int x, int y)意思就是将view移动到(x,y)坐标的位置上去。以下是scrollBy(int x,int y)的源码
public void scrollBy(int x, int y) {
scrollTo(mScrollX + x, mScrollY + y);
}
意思就显而易见了。