Search code examples
androidandroid-animationandroid-imageviewandroid-image

Fade in animation image in Android giving black screen


I want my picture to fade in (I think this is how you call it...). I am currently trying to use the alpha to do this (see below). But the alpha is getting a black screen and then showing the picture. I need the animation to show the picture in the beginning but a transparent one or very bright picture and then get darker and fill the color as the animation progresses.

Hope I explained myself correctly...

 AlphaAnimation fadein = new AlphaAnimation(0, 1);
     //fadein.setFillAfter(true);
     fadein.setDuration(1000);
     apa.startAnimation(fadein);
     animationmove=3;

Solution

  • If you want it to partially visible to start with, you can do one of the two following options:

    1. Create a low opacity image and set it as the background of the parent layout.
    2. Change the initial alpha to a small, non-zero value:

      AlphaAnimation fadein = new AlphaAnimation(0.2, 1);

    After animation, The image you animate will probably return to its original state.

    There are three "setFill..." methods you can use. fadein.setFillBefore(true) makes it start in the finished animation state, provided that you declare fadein.setFillEnabled(true).

    fadein.setFillAfter(true) makes the animated image retain its final state after animation.

    You can also declare these in the animation.xml files between the , .