点击此链接查看三种同时对View
的多个属性进行动画处理的方法:
https://developer.android.com/guide/topics/graphics/prop-animation#view-prop-animator
第一种方法是使用AnimatorSet。
以下是第二种方法:
public static ObjectAnimator ofPropertyValuesHolder (Object target,
PropertyValuesHolder... values)
API文档描述了ObjectAnimator
的此构造函数:
"当使用相同的ObjectAnimator
同时动画化多个属性时,应该使用此变体,因为PropertyValuesHolder
允许您将一组动画值与属性名称关联起来。"
例如:
Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
Keyframe kf1 = Keyframe.ofFloat(.5f, 360f);
Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
PropertyValuesHolder transX = PropertyValuesHolder.ofKeyframe("translationX", kf0, kf1, kf2);
PropertyValuesHolder transY = PropertyValuesHolder.ofKeyframe("translationY", kf0, kf1, kf2);
ObjectAnimator transAnim = ObjectAnimator.ofPropertyValuesHolder(view2animate, transX, transY);
transAnim.setDuration(5000);
transAnim.start();
上面的示例同时在x和y轴上移动view2animate
。
第3种方法是使用ViewPropertyAnimator。