Bouncer.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:androidtv-daydream 作者:
public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) {
    final float dt = dt_ms / 1000f; // seconds
    for (int i=0; i<getChildCount(); i++) {
        final View view = getChildAt(i);
        final PointF v = (PointF) view.getTag();

        // step view for velocity * time
        view.setX(view.getX() + v.x * dt);
        view.setY(view.getY() + v.y * dt);

        // handle reflections
        final float l = view.getX();
        final float t = view.getY();
        final float r = l + view.getWidth();
        final float b = t + view.getHeight();
        boolean flipX = false, flipY = false;
        if (r > mWidth) {
            view.setX(view.getX() - 2 * (r - mWidth));
            flipX = true;
        } else if (l < 0) {
            view.setX(-l);
            flipX = true;
        }
        if (b > mHeight) {
            view.setY(view.getY() - 2 * (b - mHeight));
            flipY = true;
        } else if (t < 0) {
            view.setY(-t);
            flipY = true;
        }
        if (flipX) v.x *= -1;
        if (flipY) v.y *= -1;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号