1
我想动画ViewGroup背景Drawable的alpha属性。动画绘制阿尔法属性
我使用view.getBackground()获取对背景的drawable的引用。
然后我用下面的代码(from this thread):
if (backgroundDrawable.getAlpha() == 0) {
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(backgroundDrawable, PropertyValuesHolder.ofInt("alpha", 255));
animator.setTarget(backgroundDrawable);
animator.setDuration(2000);
animator.start();
} else {
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(backgroundDrawable, PropertyValuesHolder.ofInt("alpha", 0));
animator.setTarget(backgroundDrawable);
animator.setDuration(2000);
animator.start();
}
但动画总是从阿尔法值0(意思是,当我想动画为0时,它会立即开始消失,因为它动画从0到0)。
有谁知道我该如何做这项工作?
很好的答案,但行:animator.setTarget(backgroundDrawable);是多余的,因为ofPropertyValuesHolder中的第一个参数已经定义了目标。 – yshahak 2015-06-11 16:03:10