Android 动画在视图进入暂停状态时不停止的实现方法
要在Android中实现在视图进入pause状态时动画不停止,可以通过以下步骤来实现:
- 在Activity或Fragment的onPause()方法中,调用动画的pause()方法,使动画暂停。
@Override
protected void onPause() {
super.onPause();
animation.pause();
}
- 在Activity或Fragment的onResume()方法中,调用动画的resume()方法,使动画继续播放。
@Override
protected void onResume() {
super.onResume();
animation.resume();
}
- 在Activity或Fragment的onDestroy()方法中,调用动画的cancel()方法,取消动画。
@Override
protected void onDestroy() {
super.onDestroy();
animation.cancel();
}
这样,在视图进入pause状态时,动画会暂停,而在视图恢复时,动画会继续播放。在Activity或Fragment销毁时,动画会被取消。
原文地址: https://www.cveoy.top/t/topic/pS7X 著作权归作者所有。请勿转载和采集!