要在指定时间后停止AnimationDrawable,并在onResume()中恢复,在onPause()中暂停,可以按照以下步骤进行操作:
private AnimationDrawable animationDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = findViewById(R.id.imageView);
imageView.setBackgroundResource(R.drawable.animation_drawable);
animationDrawable = (AnimationDrawable) imageView.getBackground();
}
// 在指定时间后停止AnimationDrawable
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
animationDrawable.stop();
}
}, specifiedTime);
@Override
protected void onResume() {
super.onResume();
animationDrawable.start();
}
@Override
protected void onPause() {
super.onPause();
animationDrawable.stop();
}
通过以上步骤,你可以在指定时间后停止AnimationDrawable,并在onResume()中恢复,在onPause()中暂停。