android两个animation无限循环怎么做
2个回答
推荐于2016-03-28 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517184
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向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);
或者像其他所说的,通过在一个动画结束后开始另外一个动画的方式。
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
展开全部
方法一:
①参考:http://blog.csdn.net/jiangwei0910410003/article/details/16985999
②anim中主要参数设置:
android:interpolator="@android:anim/linear_interpolator" android:repeatMode="restart" android:repeatCount="infinite"
方法二:
①Animation设置setAnimationListener(new ReStartAnimationListener())
②ReStartAnimationListener()具体实现
/** * 重复启动动画 */ private class ReStartAnimationListener implements Animation.AnimationListener { public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub animation.reset(); animation.setAnimationListener(new ReStartAnimationListener()); animation.start(); } public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } }
①参考:http://blog.csdn.net/jiangwei0910410003/article/details/16985999
②anim中主要参数设置:
android:interpolator="@android:anim/linear_interpolator" android:repeatMode="restart" android:repeatCount="infinite"
方法二:
①Animation设置setAnimationListener(new ReStartAnimationListener())
②ReStartAnimationListener()具体实现
/** * 重复启动动画 */ private class ReStartAnimationListener implements Animation.AnimationListener { public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub animation.reset(); animation.setAnimationListener(new ReStartAnimationListener()); animation.start(); } public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询