准确地说,我正在将视图拖放到列表中,当用户删除视图时,它应该以弯曲路径进入 listview 中的列表。
PS:我看过很多动画,但是是沿着 x 坐标而不是沿着 y 坐标。感谢您的所有帮助。
我已经使用 Problem 中的 ArcTranslate 类来实现弯曲动画 ,但那是用于沿 x 坐标的曲线。
弧形动画的代码:
public class ArcAnimation extends Animation {
private Point start;
private Point end;
private Point middle;
private final float mFromXValue;
private final float mToXValue;
private final float mYValue;
private final int mFromXType;
private final int mToXType;
private final int mYType;
/**
* A translation along an arc defined by three points and a Bezier Curve
*
* @param duration - the time in ms it will take for the translation to complete
* @param fromXType - One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param fromXValue - Change in X coordinate to apply at the start of the animation
* @param toXType - One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param toXValue - Change in X coordinate to apply at the end of the animation
* @param yType - One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
* @param yValue - Change in Y coordinate to apply at the middle of the animation (the radius of the arc)
*/
public ArcAnimation(long duration, int fromXType, float fromXValue,
int toXType, float toXValue, int yType, float yValue){
setDuration(duration);
mFromXValue = fromXValue;
mToXValue = toXValue;
mYValue = yValue;
mFromXType = fromXType;
mToXType = toXType;
mYType = yType;
}
/** Calculate the position on a quadratic bezier curve given three points
* and the percentage of time passed.
* from http://en.wikipedia.org/wiki/B%C3%A9zier_curve
* @param interpolatedTime - the fraction of the duration that has passed where 0<=time<=1
* @param p0 - a single dimension of the starting point
* @param p1 - a single dimension of the middle point
* @param p2 - a single dimension of the ending point
*/
private long calcBezier(float interpolatedTime, float p0, float p1, float p2){
return Math.round((Math.pow((1 - interpolatedTime), 2) * p0)
+ (2 * (1 - interpolatedTime) * interpolatedTime * p1)
+ (Math.pow(interpolatedTime, 2) * p2));
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float dx = calcBezier(interpolatedTime, start.x, middle.x, end.x);
float dy = calcBezier(interpolatedTime, start.y, middle.y, end.y);
t.getMatrix().setTranslate(dy, dx);
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
float startX = resolveSize(mFromXType, mFromXValue, height, parentHeight);
float endX = resolveSize(mToXType, mToXValue, height, parentHeight);
float middleY = resolveSize(mYType, mYValue, height, parentHeight);
float middleX = startX + ((endX-startX)/2);
start = new Point((int)startX, 0);
end = new Point((int)endX, 0);
middle = new Point((int)middleX, (int)middleY);
}
}
使用以下代码,对象直接下降到列表中,但不是以曲线方式。如何使弧形动画正常工作?
谢谢 !