Android Scroller解析

作用

这个类封装了滚动操作,如帮我们处理手指抬起来时候的滑动操作。与ViewGroup的scrollTo(),scrollBy()的生硬式移动,Scroller提供了一个更加柔和的移动效果。Scroller的坐标系跟平常我们见到的View的坐标系不太一样,Scroller向左滑值为正,向上滑为正。
注意移动的是View中的内容如图:


常用方法

  • public void abortAnimation ():取消当前的滑动动画

  • public boolean computeScrollOffset ():判断当前的滑动是否结束

  • public final int getCurrX ():获取Scroller当前水平滚动的位置,距离原点X方向的绝对值

  • public final int getCurrY ():获取Scroller当前水平滚动的位置,距离原点Y方向的绝对值

  • public final int getStartX ():起始点在X方向距离原点的绝对距离

  • public final int getStartY ():起始点在Y方向距离原点的绝对距离

  • public final boolean isFinished ():停止滚动返回true,否则返回false

  • public void startScroll (int startX, int startY, int dx, int dy):
    以提供的起始点和将要滑动的距离开始滚动。滚动会使用缺省值250ms作为持续时间。

  • public void startScroll (int startX, int startY, int dx, int dy, int duration):以提供的起始点和将要滑动的距离开始滚动。

  • public void computeScroll() {
    //由父视图调用用来请求子视图根据偏移值 mScrollX,mScrollY重新绘制,该方法为空方法 ,自定义ViewGroup必须实现方法体 ,该方法的调用在onDraw()方法中触发

猜你喜欢

转载自www.cnblogs.com/Free-Thinker/p/12027411.html