简体   繁体   中英

How to animate ImageAlpha of ImageView

Since API16 ImageView.setImageAlpha(int) should be used instead of View.setAlpha(float) for better performance.

But how can I animate that value? I tried ValueAnimator without success.

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

I mean what Chet Haase is talking about here http://youtu.be/vQZFaec9NpA?t=33m

It should be fine. Maybe you forgot to specify the animation duration, or your alpha values are wrong (negative, too small, too close to notice)?

You can always animate using custom listener. It's longer, but easier to debug:

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM