我正在使用放大动画来查看我的应用中的视图。当用户单击按钮时,下一个活动将从该按钮放大。 This是我使用下面的代码获得的。
由于在上面提到的视频中,显示的代码仅适用于软糖和以上,我必须使用下面给出的代码。
Next_Activity.java (放大动画的活动)
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);
现在,我的问题是如何撤消这个动画?我的意思是当我点击按钮时,活动会从该按钮放大。那么当按下后退按钮时,如何将活动缩小到相同的按钮?
@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);
}