Android, move bitmap along a path?

后端 未结 3 1837
無奈伤痛
無奈伤痛 2020-11-27 21:23

I would like to know if it\'s possible to select coordinates from a path to draw a bitmap over time, for example, I have an image of a sun, and I would like to move it, over

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 21:45

    Here are the animators I use:

    Purpose: Move View "view" along Path "path"

    v21+:

    ValueAnimator pathAnimator = ObjectAnimator.ofFloat(view, "x", "y", path)
    

    v11+:

    ValueAnimator pathAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
    
    pathAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    float[] point = new float[2];
    
    @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float val = animation.getAnimatedFraction();
            PathMeasure pathMeasure = new PathMeasure(path, true);
            pathMeasure.getPosTan(pathMeasure.getLength() * val, point, null);
            view.setX(point[0]);
            view.setY(point[1]);
        }
    });
    

    Similar requirement to: https://stackoverflow.com/a/30254715/4344057

提交回复
热议问题