首页 > 解决方案 > 流畅的变形动画

问题描述

如何在android中实现平滑的变形动画?

我正在使用自定义视图canvas.draw(path, paint)的方法在相机预览上渲染多边形形状。OnDraw()

路径正在呈现如下:

for (int i = 0; i < pointList.size(); i++) {
        Point currentPoint = adjustedPointList.get(i);

        if (i == 0) {
            //for the first point, we only have to move to that point
            firstPoint = currentPoint;
            mPath.moveTo(currentPoint.getX(), currentPoint.getY());
            //Animation here 

        } else {
            //otherwise we draw a line between last position and current point
            mPath.lineTo(currentPoint.getX(), currentPoint.getY());
            //Animation here

        }
    }


    //we have to draw a last line between last and first point
    if (firstPoint != null) {
        mPath.lineTo(firstPoint.getX(), firstPoint.getY());
        //Animation here
    }

我尝试了这里ObjectAnimator的课程,但没有效果。由于这在线程内部不断调用,因此形状会随着帧的变化而变化。这就是我想要在 iOS 中制作像这里一样流畅的动画的地方。我怎样才能对上面图解的渲染做同样的事情?

我还尝试了以下问题的解决方案:

DashPathEffect

路径动画

将动画师附加到路径

价值动画师

但是没有什么能达到我平滑形状转换甚至动画路径绘制的目的。目前的形状转变非常闪烁。

此外,许多用于 android 的变形动画参考使用位图或 SVG,这对我来说又没用。

我怎样才能在android中实现这个?还是有不同的方法?如果是这样,我想知道关于它的一切。谢谢!

标签: androidanimationandroid-animationandroid-canvasandroid-custom-view

解决方案


推荐阅读