-1

I have an Activity with a button. If user clicks Button, I start a service and finish this Activity. I want to fade out it. How to do it? I tried some ways but they seems not to work.

Jitesh Dalsaniya
  • 1,917
  • 3
  • 20
  • 36
TOP
  • 2,574
  • 5
  • 35
  • 60

3 Answers3

5

the smallest and best way i found is to put code:

finish();
overridePendingTransition(0, android.R.anim.fade_out);

into OnClickListener, or where ever you want to finish activity with fade.

borichellow
  • 1,003
  • 11
  • 11
1

I think I solved my problem with ObjectAnimator.

ObjectAnimator objAnimator = ObjectAnimator.ofFloat(mainView, View.ALPHA, 1.0f, 0.0f);
            obj.setDuration(2000).addListener(new AnimatorListener() {

                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    finish();
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                }
            });
            objAnimator.start();
TOP
  • 2,574
  • 5
  • 35
  • 60
0

Fade out and Fadein using Android(java)

Animation fadeIn = new AlphaAnimation(0, 1); // fadein
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(1000);

Animation fadeOut = new AlphaAnimation(1, 0);//Fadeout
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);

AnimationSet animation = new AnimationSet(false); //change to false
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

I trust this is helpful to you for more refer this link

Community
  • 1
  • 1
Siva Sonai
  • 107
  • 12