Zoom out animation - Android

≡放荡痞女 提交于 2019-12-22 01:30:52

问题


I am using zoom in animation for a view in my app. When the user clicks on a button the next activity zooms in from that button. This is what I have achieved using the code give below.

Since the in the video mentioned above, the code that was shown only worked for jellybean and above I had to use the code given below.

Next_Activity.java (The activity with zoom in 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(The Activity with button)

   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 reverse this animation? I mean when I click on the button, the activity zooms in from that button. So how do I zoom out the activity to the same button when the back button is pressed?

@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??
}

回答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);   
}


来源:https://stackoverflow.com/questions/22057925/zoom-out-animation-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!