android中View的scrollBy(int x,int y)和scrollTo(int x,int y)的区别

来源:互联网 发布:行知职业技术学校地址 编辑:程序博客网 时间:2024/04/28 03:20

先看看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
xthe amount of pixels to scroll by horizontallyythe 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
xthe x position to scroll toythe 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);    }
意思就显而易见了。

0 2
原创粉丝点击