天天育儿网,内容丰富有趣,生活中的好帮手!
天天育儿网 > android 动画停止播放 Android动画暂停和播放问题

android 动画停止播放 Android动画暂停和播放问题

时间:2022-04-08 08:16:45

相关推荐

android 动画停止播放 Android动画暂停和播放问题

由于您已经扩展了有关您明确想要使用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动画暂停和播放问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。