Reduce Animation - Android

I use zoom animation for viewing in my application. When the user clicks on the button, the next action is scaled from that button. This is what I achieved using the code below.

Since the video above only shows the code that was shown only for jellybean, and above I had to use the code below.

Next_Activity.java (activity with increasing animation)

    Bundle b = getIntent().getExtras(); // Bundle passed from previous activity to this activity

    x = b.getInt("X");              //b is button in previous activity
    y = b.getInt("Y");              //b is button in previous activity
    xh = b.getInt("XH");            //b is button in previous activity
    yh = b.getInt("YH");            //b is button in previous activity

    AnimationSet set = new AnimationSet(true);

    width = display.getWidth();
    height = display.getHeight();


    Animation scale = new ScaleAnimation( (float)xh/width, 1f, (float)yh/height , 1f, x, y);

    Animation alpha = new AlphaAnimation(.75f, 1f);

    set.addAnimation(scale);
    set.addAnimation(alpha);

    set.setDuration(300);

    main.startAnimation(set);            //main is rootLayout of this activity

Main_Activity (activity button with)

   Bundle bundle = new Bundle();
   int[] xy = new int[2];

   button.getLocationOnScreen(xy);

   bundle.putInt("X", xy[0] + (b.getWidth() / 2));
   bundle.putInt("Y", xy[1] + (b.getHeight() / 2));
   bundle.putInt("XH", b.getWidth());
   bundle.putInt("YH", b.getHeight());

   Intent startnextactivity = new Intent(Table_main.this,Next_Activity.class);
   startnextactivity.putExtras(bb);
   startActivity(startnextactivity);

Now, my question is: how do I cancel this animation? I mean, when I click on a button, activity increases from that button. So, how to reduce the scale of activity by the same button when you click the back button?

@Override
public void onBackPressed()
{
Animation scale = new ScaleAnimation( (float)xh/width, 1f, (float)yh/height , 1f, x, y);
// What is the zoom out animation of the above line??
}
0
1
@Override
public void onBackPressed() {
    Bundle b = getIntent().getExtras();
    x = b.getInt("X");
    y = b.getInt("Y");
    xh = b.getInt("XH");
    yh = b.getInt("YH");
    AnimationSet set = new AnimationSet(true);
    width = display.getWidth();
    height = display.getHeight();
    Animation scale = new ScaleAnimation((1f, (float) xh/width, 1f, (flaot) yh/height, x, y);
    Animation alpha = new AlphaAnimation(.75f, 1f);
    set.addAnimation(scale);
    set.addAnimation(alpha);
    set.setDuration(300);
    main.startAnimation(set);   
}
+1

All Articles