private FloatingActionButton fab;移动的imageview,一个可以设置阴影的imageview
/*设置动画路径*/
public void setPath(){
path = new AnimatorPath();
path.moveTo(0,0);
path.lineTo(400,400);
path.secondBesselCurveTo(600, 200, 800, 400); //订单
path.thirdBesselCurveTo(100,600,900,1000,200,1200);
}
设置路径。这个path是自定义的,里面只有一些动作的类型属性和点的属性
/**
* 设置动画
* @param view 使用动画的View
* @param propertyName 属性名字
* @param path 动画路径集合
*/
private void startAnimatorPath(View view, String propertyName, AnimatorPath path) {
ObjectAnimator anim = ObjectAnimator.ofObject(this, propertyName, new PathEvaluator(), path.getPoints().toArray());
anim.setInterpolator(new DecelerateInterpolator());
anim.setDuration(3000);
anim.start();
}
/**
* 设置View的属性通过ObjectAnimator.ofObject()的反射机制来调用
* @param newLoc
*/
public void setFab(PathPoint newLoc) {
fab.setTranslationX(newLoc.mX);
fab.setTranslationY(newLoc.mY);
}
这里是反射机制调用activity里面的fab控件。也是属性,设置他的XY移动的值
public class PathEvaluator implements TypeEvaluator<PathPoint> {
/**
* @param t :执行的百分比
* @param startValue : 起点
* @param endValue : 终点
* @return
*/
@Override
public PathPoint evaluate(float t, PathPoint startValue, PathPoint endValue) {
float x, y;
float oneMiunsT = 1 - t;
//三阶贝塞尔曲线
if (endValue.mOperation == PathPoint.THIRD_CURVE) {
x = startValue.mX*oneMiunsT*oneMiunsT*oneMiunsT+3*endValue.mContorl0X*t*oneMiunsT*oneMiunsT+3*endValue.mContorl1X*t*t*oneMiunsT+endValue.mX*t*t*t;
y = startValue.mY*oneMiunsT*oneMiunsT*oneMiunsT+3*endValue.mContorl0Y*t*oneMiunsT*oneMiunsT+3*endValue.mContorl1Y*t*t*oneMiunsT+endValue.mY*t*t*t;
//二阶贝塞尔曲线
}else if(endValue.mOperation == PathPoint.SECOND_CURVE){
x = oneMiunsT*oneMiunsT*startValue.mX+2*t*oneMiunsT*endValue.mContorl0X+t*t*endValue.mX;
y = oneMiunsT*oneMiunsT*startValue.mY+2*t*oneMiunsT*endValue.mContorl0Y+t*t*endValue.mY;
//直线
}else if (endValue.mOperation == PathPoint.LINE) {
//x起始点+t*起始点和终点的距离
x = startValue.mX + t * (endValue.mX - startValue.mX);
y = startValue.mY + t * (endValue.mY - startValue.mY);
} else {
x = endValue.mX;
y = endValue.mY;
}
return PathPoint.moveTo(x,y);
}
}
这个自定义估值器,能够根据传入的值,不断改变返回值的X,Y坐标
原文链接:http://www.apkbus.com/blog-865677-63456.html
打开App,阅读手记