TextView animation - fade in, wait, fade out

后端 未结 5 944
广开言路
广开言路 2020-12-30 01:00

I am making a picture gallery app. I current have a imageview with a text view at the bottom. Currently it is just semitransparent. I want to make it fade in, wait 3 second,

5条回答
  •  忘掉有多难
    2020-12-30 01:15

    protected AlphaAnimation fadeIn = new AlphaAnimation(0.0f , 1.0f ) ; 
    protected AlphaAnimation fadeOut = new AlphaAnimation( 1.0f , 0.0f ) ; 
    txtView.startAnimation(fadeIn);
    txtView.startAnimation(fadeOut);
    fadeIn.setDuration(1200);
    fadeIn.setFillAfter(true);
    fadeOut.setDuration(1200);
    fadeOut.setFillAfter(true);
    fadeOut.setStartOffset(4200+fadeIn.getStartOffset());
    

    Works perfectly for white backgrounds. Otherwise, you need to switch values when you instantiate AlphaAnimation class. Like this:

    AlphaAnimation fadeIn = new AlphaAnimation( 1.0f , 0.0f ); 
    AlphaAnimation fadeOut = new AlphaAnimation(0.0f , 1.0f ); 
    

    This works with black background and white text color.

提交回复
热议问题