android中沿y坐标的曲线动画
确切地说,我正在把视图放到列表中,当用户把视图放到列表中时,它应该沿着一条弯曲的路径到达listview中的列表 PS:我看过很多动画,但是沿着x坐标,而不是y坐标。 谢谢你的帮助 我使用了来自的ArcTranslate类 但这是沿着x坐标的曲线 圆弧动画的代码:android中沿y坐标的曲线动画,android,android-listview,android-animation,Android,Android Listview,Android Animation,确切地说,我正在把视图放到列表中,当用户把视图放到列表中时,它应该沿着一条弯曲的路径到达listview中的列表 PS:我看过很多动画,但是沿着x坐标,而不是y坐标。 谢谢你的帮助 我使用了来自的ArcTranslate类 但这是沿着x坐标的曲线 圆弧动画的代码: public class ArcAnimation extends Animation { private Point start; private Point end; private Point middle; priv
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);
}
}
公共类ArcAnimation扩展了动画{
私人点启动;
专用点端;
私家点中间;
私有最终浮动mFromXValue;
私人最终浮动mToXValue;
私人最终浮动价值;
私有最终int-mFromXType;
私有final int mToXType;
私有最终int-mYType;
/**
*沿三点和贝塞尔曲线定义的圆弧的平移
*
*@param duration-翻译完成所需的时间(毫秒)
*@param fromXType-Animation.ABSOLUTE、Animation.RELATIVE_TO_SELF或Animation.RELATIVE_TO_PARENT中的一种。
*@param fromXValue-更改X坐标以在动画开始时应用
*@param toXType-Animation.ABSOLUTE、Animation.RELATIVE_TO_SELF或Animation.RELATIVE_TO_PARENT中的一种。
*@param toXValue-将X坐标更改为在动画结束时应用
*@param yType-Animation.ABSOLUTE、Animation.RELATIVE_TO_SELF或Animation.RELATIVE_TO_PARENT中的一种。
*@param yValue-更改Y坐标以应用于动画中间(圆弧半径)
*/
公共ArcAnimation(长持续时间,int fromXType,float fromXValue,
int-toXType,float-toXValue,int-yType,float-yValue){
设置持续时间(持续时间);
mFromXValue=fromXValue;
mToXValue=toXValue;
mYValue=yValue;
mFromXType=fromXType;
mToXType=toXType;
mYType=yType;
}
/**计算给定三个点的二次贝塞尔曲线上的位置
*以及时间流逝的百分比。
*从http://en.wikipedia.org/wiki/B%C3%A9zier_curve
*@param interpolatedTime-已过的持续时间的分数,其中0您尝试了什么?对于动画,如果您将我们链接到可以看到您正在努力的动画的位置,以确保我们在同一页上,可能会很好。编辑了问题,Thanks@Preethi你做到了吗?