How to create ObjectAnimator with valueType - pathType programmatically?

人盡茶涼 提交于 2019-12-07 00:19:33

Using PathAnimatorInflater class and rewriting the setupAnimatorForPath to accept Strings instead TypedArray it is possible. Here is a method that uses this -

private ObjectAnimator getAnimator(AnimatedVectorDrawable vector, int in, int out, int delay) {
    ObjectAnimator animator = new ObjectAnimator();
    animator.setTarget(vector);
    animator.setPropertyName("pathData");
    TypeEvaluator evaluator = PathAnimatorInflater.setupAnimatorForPath(animator, getResources().getString(in), getResources().getString(out));
    if (evaluator == null) {
        return null;
    }
    animator.setEvaluator(evaluator);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setDuration(3000);
    animator.setStartDelay(delay);
    return animator;
}

But to use this with AnimatedVectorDrawable it needs some changes in Vector classes also.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!