源码学习:Scroller的API
博客专区 > kim366 的博客 > 博客详情
源码学习:Scroller的API
kim366 发表于2年前
源码学习:Scroller的API
  • 发表于 2年前
  • 阅读 4
  • 收藏 0
  • 点赞 2
  • 评论 0

移动开发云端新模式探索实践 >>>   

源码学习:Scroller的API

在View类中
    /**
     * Called by a parent to request that a child update its values for mScrollX
     * and mScrollY if necessary. This will typically be done if the child is
     * animating a scroll using a { @link android.widget.Scroller Scroller}
     * object.
     */
      public void computeScroll() {
     }

     computeScroll:主要功能是计算拖动的位移量、更新背景、设置要显示的屏幕(setCurrentScreen(mCurrentScreen);)。

     重写computeScroll()的原因

     调用startScroll()是不会有滚动效果的,只有在computeScroll()获取滚动情况,做出滚动的响应computeScroll在父控件执行drawChild时,会调用这个方法


Scroller类中
    /**
     * Start scrolling by providing a starting point and the distance to travel.
     * The scroll will use the default value of 250 milliseconds for the
     * duration.
     *
     * @param startX Starting horizontal scroll offset in pixels. Positive
     * numbers will scroll the content to the left.
     * @param startY Starting vertical scroll offset in pixels. Positive numbers
     * will scroll the content up.
     * @param dx Horizontal distance to travel. Positive numbers will scroll the
     * content to the left.
     * @param dy Vertical distance to travel. Positive numbers will scroll the
     * content up.
     */
    public void startScroll(int startX, int startY, int dx, int dy) {
         startScroll(startX, startY, dx, dy, DEFAULT_DURATION);
    }

    /**
     * Start scrolling by providing a starting point, the distance to travel,
     * and the duration of the scroll.
     *
     * @param startX Starting horizontal scroll offset in pixels. Positive
     * numbers will scroll the content to the left.
     * @param startY Starting vertical scroll offset in pixels. Positive numbers
     * will scroll the content up.
     * @param dx Horizontal distance to travel. Positive numbers will scroll the
     * content to the left.
     * @param dy Vertical distance to travel. Positive numbers will scroll the
     * content up.
     * @param duration Duration of the scroll in milliseconds.
     */
    public void startScroll(int startX, int startY, int dx, int dy, int duration) {
          mMode = SCROLL_MODE;
          mFinished = false;
          mDuration = duration;
          mStartTime = AnimationUtils.currentAnimationTimeMillis();
          mStartX = startX;
          mStartY = startY;
          mFinalX = startX + dx;
          mFinalY = startY + dy;
          mDeltaX = dx;
          mDeltaY = dy;
          mDurationReciprocal = 1.0f / (float) mDuration;
    }



  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 1
博文 129
码字总数 0
×
kim366
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: