2011-10-28 55 views
2

我需要了解Android上的動畫。動畫與Android

例如,我的應用程序以底部有一個按鈕的活動開始,當用戶點擊按鈕時,我希望另一個活動顯示爲從下到上的動畫,我希望該按鈕變成「標題「這第二項活動。

我該如何做到這一點?

謝謝

丹尼爾

謝謝DecodeGnome的答案!有用!

但我有一些問題與動畫當我想結束這種活動,我創建了一個anim_out.xml:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<translate 
    android:fromXDelta="0%p" 
    android:fromYDelta="0%p" 
    android:toXDelta="0" 
    android:toYDelta="100%p" 
    android:duration="300" /> 
</set> 

但這不起作用(什麼是用於overridePendingTransition的第二個參數?)。

我嘗試調用的onStop新overridePendingTransition()函數:

public void onStop(){ 
    super.onStop(); 
    overridePendingTransition(R.anim.top_to_bottom, R.anim.top_to_bottom); 

}

但是,當我打電話完成的第二個活動,我仍然看到默認的動畫(從左至右)!

再次感謝您對誰就會幫助我。

+0

我通常覆蓋後退按鈕, \t @覆蓋 \t公共布爾的onkeydown(INT的keyCode,KeyEvent的事件){ \t \t如果(的keyCode == KeyEvent.KEYCODE_BACK){ \t \t \t光潔度(); \t \t \t \t \t overridePendingTransition(R.anim.in,R.anim。出); \t \t \t return true; \t \t} \t \t return super.onKeyDown(keyCode,event); \t} – DecodeGnome

回答

4

1)創建一個名爲阿尼姆在res文件夾的文件夾

2)添加2個新的XML動畫那裏(例如,anim_in.xml & anim_out.xml)

3)把此行的代碼在新活動創建:

overridePendingTransition(R.anim.anim_in,R.anim.anim_out);

Anim_in.xml例如:

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <translate 
     android:fromXDelta="0%p" 
     android:fromYDelta="100%p" 
     android:toXDelta="0" 
     android:toYDelta="0%p" 
     android:duration="300" /> 
</set> 

4)將在所述第二活動的佈局的頂部的按鈕(報頭)。

+0

你當然也可以在返回時重寫動畫,只需在創建Intent fr時返回overridePendingTransition()。 – DecodeGnome

+1

我遇到了同樣的問題,SO上的其他問題在startActivity(intent)之後的線上有overridePendingAnimation()。第3號是別人似乎忘記或遺漏的關鍵。 –

+0

只是不起作用。 – m0skit0

-1

使用此代碼:

 public void onBackPressed() { 
     super.onBackPressed(); 
     overridePendingTransition(R.anim.top_to_bottom, R.anim.top_to_bottom); 
}