Skip to content Skip to sidebar Skip to footer

Change Value In Objectanimator Of Animatorset Programmatically

I'd like to change a value of an ObjectAnimator which is part of an AnimatorSet, which is coded in Xml in a designated file in the animator directory. I don't want to replace the X

Solution 1:

It's possible.

    AnimatorSet animatorSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.anim_yours);

    List<Animator> animators = animatorSet.getChildAnimations();
    for (int i = 0; i < animators.size(); i++) {
        Animator animator = animators.get(i);
        if (animator instanceof ObjectAnimator) {
            ObjectAnimator objectAnimator = (ObjectAnimator) animator;
            if ("rotationY".equals(objectAnimator.getPropertyName())) {
                float fromValue = -100;
                float toValue = 0;
                objectAnimator.setFloatValues(fromValue, toValue);
            }
        }
    }
    // and you use changed AnimoatorSet..

Post a Comment for "Change Value In Objectanimator Of Animatorset Programmatically"