由于您已经扩展了有关您明确想要使用AnimationSet的更多信息,我找到了另一个适合您的解决方案.
示例代码:
为了取消AnimationSet,您需要扩展AnimationSet的类:
public class CustomAnimationSet extends AnimationSet {
private AnimationListener mCustomAnimationSetListener;
public CustomAnimationSet(boolean interpolator) {
super(interpolator);
}
public CustomAnimationSet(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setAnimationListener(AnimationListener listener) {
super.setAnimationListener(listener);
mCustomAnimationSetListener = listener;
}
/**
* Your cancel method....
*/
public void cancel() {
// Make sure you're cancelling an ongoing AnimationSet.
if(hasStarted() && !hasEnded()) {
if(mCustomAnimationSetListener != null) {
mCustomAnimationSetListener.onAnimationEnd(this);
}
}
// Reset the AnimationSet's start time.
setStartTime(Float.MIN_VALUE);
}
}
在您的Activity类中:
private CustomAnimationSet mAnimationSet;
// Init stuff.
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.onPlayButton:
// Might wanna add Animations before starting next time?
mAnimationSet.start();
case R.id.onPauseButton:
mAnimationSet.cancel();
mAnimationSet.reset();
}
}
这只是一个例子.目前我没有机会自己测试,这只是为了示例目的.
如果觉得《android 动画停止播放 Android动画暂停和播放问题》对你有帮助,请点赞、收藏,并留下你的观点哦!