3

我在互联网上搜索了这个没有成功。我需要沿路径为 ImageView 设置动画。我使用以下方法创建了一个路径:

Path path = new Path()    
path.moveTo(0, 0);
path.lineTo(184,776);
path.lineTo(184,780);
path.lineTo(184,790);
path.lineTo(184,810);
path.lineTo(230, 900);

ImageView img = new ImageView(this);

有什么办法可以沿路径移动 img 吗?谢谢你们

4

1 回答 1

2

以下是我使用的动画师:

目的:沿路径“路径”移动视图“视图”

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]);
    }
});

同:Android,沿路径移动位图?

于 2015-05-15T09:44:20.020 回答