0
我在我的應用程序中使用放大動畫的視圖。當用戶點擊一個按鈕時,下一個活動從該按鈕中放大。 This是我使用下面給出的代碼實現的。縮小動畫 - Android
由於在上面提到的視頻中,顯示的代碼僅適用於糖果軟糖和以上我不得不使用下面給出的代碼。
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??
}
我能明白這一點我自己。但是,如何反轉放大動畫?你可以告訴我這條線的縮小動畫 '動畫scale = new ScaleAnimation((float)xh/width,1f,(float)yh/height,1f,x,y);' –
@DroidFan我是害怕我不知道'ScaleAnimation'構造函數中的六個參數是指什麼。如果我這樣做了,我可能會幫助你,但到現在爲止,他們對我來說是任意數字。 – Adam
請再次查看代碼。我已經發布了這兩個活動以及參數。我無法做的是扭轉動畫線。謝謝! –