在我的应用程序中有按钮完成活动但是在点击关闭按钮活动后立即关闭,我想要一些动画然后完成活动。
这是我的代码,但这不起作用。
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
如何为此活动添加动画。
更新
我创建了两个动画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()
}
你能告诉我我做错了什么吗?
答案 0 :(得分:0)
你可以像这样修改你的代码
public void close(View view){
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
this.finish();
}
希望这有助于你,如果有任何问题你可以问......