2012-06-02 161 views
5

我想在Android中從一個Activity創建動畫轉換。但在動畫期間,會出現黑色背景的短暫停頓,然後顯示下一個要顯示的動畫的動畫。Android - 在動畫期間保持活動

我想保持第一個Activity完好無損,所以第二個Activity將動畫並重疊第一個Activity。我該如何實現這種行爲?

這裏是我的兩個當前動畫XML文件,這些文件沒有做什麼,我想要實現:

hold.xml

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

    <translate 
     android:duration="2000" 
     android:zAdjustment="bottom" /> 

</set> 

enter.xml

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

    <translate 
     android:duration="2000" 
     android:fromXDelta="90%" 
     android:fromYDelta="0%" 
     android:toXDelta="0%" 
     android:toYDelta="0%" 
     android:zAdjustment="top" /> 

</set> 

我的Java代碼:

starter.overridePendingTransition(R.anim.enter, 
       R.anim.hold); 

預先感謝您, 專利

回答

-1

默認的動畫從Activty過渡到活動B被設備依賴。如果屏幕短時間變黑,那是因爲您的設備以這種方式實現了這一功能......但是,您可以覆蓋應用程序的主題所使用的動畫,以將自定義動畫應用於活動之間的切換。

+0

請提供的如何重寫主題過渡動畫任何代碼或示例(而不是活性) –

9

輸入活動的動畫

startActivity(new Intent(this, AnimaitonActivity.class)); 
overridePendingTransition(R.anim.pull_up_from_bottom, R.anim.hold); 

退出活動的動畫

finish(); 
overridePendingTransition(R.anim.hold, R.anim.push_out_to_bottom); 

pull_up_from_bottom.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="1000" 
    android:fromYDelta="100%" 
    android:toYDelta="0%" /> 

push_out_to_bottom.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="1000" 
    android:fromYDelta="0%" 
    android:toYDelta="100%" /> 

hold.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false" > 
    <translate 
     android:duration="2000" 
     android:zAdjustment="bottom" /> 
</set>