这是我想用来实现我的需求的方法。
/**
* Constructs and returns an ObjectAnimator that animates the target using a multi-float setter
* along the given <code>Path</code>. A <code>Path</code></> animation moves in two dimensions,
* animating coordinates <code>(x, y)</code> together to follow the line. In this variation, the
* coordinates are float x and y coordinates used in the first and second parameter of the
* setter, respectively.
*
* @param target The object whose property is to be animated. This object may
* have a public method on it called <code>setName()</code>, where <code>name</code> is
* the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
* be the case-sensitive complete name of the public setter method.
* @param propertyName The name of the property being animated or the name of the setter method.
* @param path The <code>Path</code> to animate values along.
* @return An ObjectAnimator object that is set up to animate along <code>path</code>.
*/
public static ObjectAnimator ofMultiFloat(Object target, String propertyName, Path path) {
PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, path);
return ofPropertyValuesHolder(target, pvh);
}
但令我困惑的是,Path是两个维度,它返回的值是一个点(也是两个维度),那么应该传递给参数propertyName的值是什么?
这是我的代码,但我知道我传递的价值一定是错的。
mPath.reset();
mPath.rQuadTo(controlX, controlY, destinationX, destinationY);
ObjectAnimator objectAnimator = ObjectAnimator.ofMultiFloat(view, "translationX", mPath);
objectAnimator.setDuration(5000);
objectAnimator.start();
提前致谢。