如何为ImageView的ImageAlpha制作动画

时间:2015-01-27 12:25:41

标签: android animation imageview alpha

由于应使用API​​16 ImageView.setImageAlpha(int)而不是View.setAlpha(float)以获得更好的性能。

但我怎样才能为这个值增添动感?我尝试过ValueAnimator但没有成功。

ObjectAnimator.ofInt(imageView, "imageAlpha", 0).start();

我的意思是Chet Haase在这里谈论http://youtu.be/vQZFaec9NpA?t=33m

1 个答案:

答案 0 :(得分:3)

应该没问题。也许你忘了指定动画持续时间,或者你的alpha值是错误的(负数,太小,太接近通知)?

您始终可以使用自定义侦听器设置动画。它更长,但更容易调试:

ValueAnimator animator = ValueAnimator.ofInt(0,255);
animator.setDuration(300);
animator.setInterpolator(new DecelerateInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        imageView.setImageAlpha(valueAnimator.getAnimatedValue());
    }
});
animator.start();