在 onDestroy 或 OnDestroyView 之前为片段中的视图设置动画
Animate a view in fragment before onDestroy or OnDestroyView
我还没有发现任何几乎相关的东西。
如何在调用 onDestroy
和 onDestroyView
super
之前为视图设置动画?
我试过
@Override
public void onDestroyView() {
Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.fade_out_fast);
mBackgroundView.setAnimation(fadeOut);
super.onDestroyView();
}
这样super.onDestroyView会立即停止动画。
设置 fadeOut
的侦听器,然后调用 MyFrag.super.onDestroyView()
onAnimationEnd()
也不起作用,因为必须在方法本身内部调用 super。
我该怎么做?提前致谢!
我终于做到了。
这项工作是通过回调接口和 Activity 中的 onBackPressed 按钮完成的。
public interface UiCallback {
void update();
}
在activity中:
UiCallback mUiCallbackInstance = new UiCallback() {
public void update( /* Remove the fragment from stack here */)
}
@Override
public void onBackPressed() {
mFragmentInstance.remove(mUiCallbackInstance)
}
片段中:
public void remove(UiCallback callback) {
Animation anim = AnimationUtils.loadAnimation(...);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
callback.update();
}
})
// start animation
}
我还没有发现任何几乎相关的东西。
如何在调用 onDestroy
和 onDestroyView
super
之前为视图设置动画?
我试过
@Override
public void onDestroyView() {
Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.fade_out_fast);
mBackgroundView.setAnimation(fadeOut);
super.onDestroyView();
}
这样super.onDestroyView会立即停止动画。
设置 fadeOut
的侦听器,然后调用 MyFrag.super.onDestroyView()
onAnimationEnd()
也不起作用,因为必须在方法本身内部调用 super。
我该怎么做?提前致谢!
我终于做到了。
这项工作是通过回调接口和 Activity 中的 onBackPressed 按钮完成的。
public interface UiCallback {
void update();
}
在activity中:
UiCallback mUiCallbackInstance = new UiCallback() {
public void update( /* Remove the fragment from stack here */)
}
@Override
public void onBackPressed() {
mFragmentInstance.remove(mUiCallbackInstance)
}
片段中:
public void remove(UiCallback callback) {
Animation anim = AnimationUtils.loadAnimation(...);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
callback.update();
}
})
// start animation
}