android两个animation无限循环怎么做
2014-12-13 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464978
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
据我所知,想直接给AnimationSet设置重复,是不行的。不过你可以这样来:
final int transDuration = 2000;
final int alphaDuration = 1000;
AnimationSet set = new AnimationSet(false);
set.setRepeatMode(Animation.RESTART);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 300);
translateAnimation.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float arg0) {
float ret = arg0 / (1.0f * transDuration / (transDuration + alphaDuration));
return ret < 1 ? ret : 1;
}
});
translateAnimation.setRepeatCount(Animation.INFINITE);
translateAnimation.setDuration(transDuration + alphaDuration);
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setRepeatCount(Animation.INFINITE);
alphaAnimation.setDuration(alphaDuration);
alphaAnimation.setStartOffset(transDuration);
set.addAnimation(translateAnimation);
set.addAnimation(alphaAnimation);
view.startAnimation(set);
或者像其他所说的,通过在一个动画结束后开始另外一个动画的方式。
final int transDuration = 2000;
final int alphaDuration = 1000;
AnimationSet set = new AnimationSet(false);
set.setRepeatMode(Animation.RESTART);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 300);
translateAnimation.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float arg0) {
float ret = arg0 / (1.0f * transDuration / (transDuration + alphaDuration));
return ret < 1 ? ret : 1;
}
});
translateAnimation.setRepeatCount(Animation.INFINITE);
translateAnimation.setDuration(transDuration + alphaDuration);
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setRepeatCount(Animation.INFINITE);
alphaAnimation.setDuration(alphaDuration);
alphaAnimation.setStartOffset(transDuration);
set.addAnimation(translateAnimation);
set.addAnimation(alphaAnimation);
view.startAnimation(set);
或者像其他所说的,通过在一个动画结束后开始另外一个动画的方式。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询