2015-04-20 43 views
1

我想实现弯曲运动的影响,每 http://developer.android.com/training/material/animations.html#CurvedMotion如何实现Android棒棒糖曲线运动API?

这是我的代码,它只是我的动画视图线性地从我的出发共同ORDS我结束共同ORDS - 没有曲线。我错过了什么?

HomeView homeView = (HomeFragment) adapter.getFragmentAtPosition(MainTab.HOME.getPositionId()); 
    //ending x co-ordinates 
    float x1 = fab.getX(); 
    float y1 = fab.getY(); 

    //ending x co-ordinates 
    float x3 = homeView.getCenterXofStatusCard(fab); 
    float y3 = homeView.getCenterYofStatusCard(fab); 

    final Path path = new Path(); 
    path.moveTo(x1, y1); 

    final float x2 = (x3 + x1)/2; 
    final float y2 = (y3 + y1)/2; 
    path.cubicTo(x1, y1, x2, y2, x3, y3); 

    ObjectAnimator anim = ObjectAnimator.ofFloat(fab, View.X, View.Y, path); 
    anim.start(); 

回答

4

我正在使用坐标来生成直线贝塞尔曲线。这里有更好的坐标来创建曲线。

 path.moveTo(x1, y1); 
     final float x2 = (x1 + x3)/2; 
     final float y2 = y1; 

     path.quadTo(x2, y2, x3, y3); 
+0

你可以在Path中使用arcTo方法来创建曲线,对吗? – Siva