Search code examples
androidimageviewfade

How to set image alpha back to normal


I am trying to have an image of a check mark or an image of a cross appear whether the user got something wrong or right. I then want the image to fade, which I have done to a level that I like, but the problem is, is the image doesn't re-appear after it fades. The code in question is below:

private void aniCross(){
    cross.setVisibility(View.VISIBLE);
    cross.animate().alpha(0).setDuration(1000);
}

Here I call an animate cross method that will set the visibility to visible (I set the image to be invisible at the start of the onCreate), and then it will animate the image. The animation takes the alpha to a value of 0 in a time interval of 1000ms. After the cross becomes invisible, I want it to be able to be displayed again and again for as long as it needs to, but still fading out after each time it is displayed.

I have tried doing things like cross.setAlpha(255) but that didn't seem to help the problem.


Solution

  • Don't like answering my own question, but I was able to fix this problem. Use cross.setAlpha(1f) instead of cross.setAlpha(255). I guess setAlpha takes a float form 0 to 1 instead of 0 to 255.