javaandroidimageviewviewpropertyanimator

Fade in image with ViewPropertyAnimator


I'm trying to fade in an ImageView with a variable duration using ViewPropertyAnimator, but I can't get it to work.

This is code I use for fade out and it works great:

final ImageView imageView = (ImageView)mView.findViewById(R.id.image_view);
Picasso.with(mView.getContext()).load(mItem.thumbnailURL).into(imageView, new Callback() {
      @Override
      public void onSuccess() {
           imageView.animate().alpha(0).setDuration(duration).start();
      }
      ...
});

but if I try to reverse the direction for a fade in, the image never shows up:

final ImageView imageView = (ImageView)mView.findViewById(R.id.image_view);
imageView.setAlpha(0);

Picasso.with(mView.getContext()).load(mItem.thumbnailURL).into(imageView, new Callback() {
      @Override
      public void onSuccess() {
           imageView.animate().alpha(1).setDuration(duration).start();
      }
      ...
});

Why does the alpha value never increase? Is the animation running on a different alpha channel than setAlpha?


Solution

  • Change deprecated "setAlpha(int alpha)" to "setAlpha (float alpha)", and it will work

    imageView.setAlpha(0f);