缩小动画-Android [英] Zoom out animation - Android

查看:155
本文介绍了缩小动画-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用放大动画在我的应用程序中查看.当用户单击按钮时,下一个活动将从该按钮放大. 是我使用下面给出的代码实现的.

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 (具有放大动画的活动)

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 (带有按钮的活动)

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

推荐答案

@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);   
}

这篇关于缩小动画-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆