在我的應用程序中有按鈕來完成活動,但點擊關閉按鈕活動後立即關閉,我想要一些動畫,然後完成活動。關閉時添加動畫活動 - android
這是我的代碼,但這是行不通的。
public void close(View view){
Animation fadeOut = new AlphaAnimation(1, 0);//Fadeout
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);
AnimationSet animation = new AnimationSet(false); //change to false
animation.addAnimation(fadeOut);
animation.setAnimationListener(new Animation.AnimationListener(){
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
this.finish(); // Error: cannot resolve method
}
});
this.setAnimation(animation); // Error: cannot resolve method
}
Error: cannot resolve method
如何爲此活動添加動畫。
UPDATE:
我創建了兩個動畫fade_in.xml
和fade_out.xml
之後,我添加overridePendingTransition
但它不工作。
下面是新的代碼:
fade_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="3000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0.0" />
</set>
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="3000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
接近()
public void close(View view){
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
this.finsih()
}
你能讓我知道我做錯了什麼嗎?
你在哪裏見過像'setAnimation(方法)'上活動?要在活動切換或完成時使用動畫,您需要使用'overridePendingTransition(R.anim.enterAnim,R.exitAnim);' – Opiatefuchs
請參閱此處:https://stackoverflow.com/questions/2651360/how-to-provide-動畫時調用另一個活動在Android中 – Opiatefuchs
我沒有開始任何其他活動。我只需要關閉這個 –