我在互联网上搜索这个没有成功。我需要沿路径动画一个ImageView。我用:
创建了一个PathPath 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吗? 谢谢大家
答案 0 :(得分: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]);
}
});
相同