Making a smooth fade out for imageview in android

后端 未结 2 804
既然无缘
既然无缘 2020-12-25 14:57

I managed to make the imageView dissapear after 10 seconds(a tutorial image on my mainActivity). But i want to make a smooth fade out because like this it doesn`t look good,

2条回答
  •  清酒与你
    2020-12-25 15:29

    Replace img.setVisibility(View.GONE) in your code with a call to fadeOutAndHideImage(img) which is defined like this:

      private void fadeOutAndHideImage(final ImageView img)
      {
        Animation fadeOut = new AlphaAnimation(1, 0);
        fadeOut.setInterpolator(new AccelerateInterpolator());
        fadeOut.setDuration(1000);
    
        fadeOut.setAnimationListener(new AnimationListener()
        {
                public void onAnimationEnd(Animation animation) 
                {
                      img.setVisibility(View.GONE);
                }
                public void onAnimationRepeat(Animation animation) {}
                public void onAnimationStart(Animation animation) {}
        });
    
        img.startAnimation(fadeOut);
    }
    

    It will apply the fade out animation first, then will hide the image view.

提交回复
热议问题