Android 如何设置ImageView的ImageAlpha动画

Android 如何设置ImageView的ImageAlpha动画,android,animation,imageview,alpha,Android,Animation,Imageview,Alpha,因为API16 ImageView.setImageAlpha(int)应该使用,而不是View.setAlpha(float)以获得更好的性能 但是,我如何设置该值的动画?我尝试了一个动画师,但没有成功 ObjectAnimator.ofInt(imageView,“imageAlpha”,0.start() 我是说切特·哈斯在这里所说的应该没问题。可能您忘记指定动画持续时间,或者您的alpha值错误(负数、太小、太近以至于无法注意到) 始终可以使用自定义侦听器设置动画。它更长,但更易于调试:

因为API16 ImageView.setImageAlpha(int)应该使用,而不是View.setAlpha(float)以获得更好的性能

但是,我如何设置该值的动画?我尝试了一个动画师,但没有成功

ObjectAnimator.ofInt(imageView,“imageAlpha”,0.start()


我是说切特·哈斯在这里所说的应该没问题。可能您忘记指定动画持续时间,或者您的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();

view.animate()。setImageAlpha采用不同的路径来避免这些性能影响。