AnimatorSet.setDuration问题
2015-01-10 14:38
309 查看
最近在使用RippleBackground这个开源代码,做水波纹的动画效果,里面有一部分代码是这样的:
animatorSet = new AnimatorSet();
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.setDuration(rippleDurationTime);
animatorList = new ArrayList<Animator>();
for (int i = 0; i < rippleAmount; i++) {
RippleView rippleView = new RippleView(getContext());
addView(rippleView, rippleParams);
rippleViewList.add(rippleView);
final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleXAnimator.setStartDelay(i * rippleDelay);
animatorList.add(scaleXAnimator);
final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleYAnimator.setStartDelay(i * rippleDelay);
animatorList.add(scaleYAnimator);
final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
alphaAnimator.setStartDelay(i * rippleDelay);
animatorList.add(alphaAnimator);
}
animatorSet.playTogether(animatorList);这是那个波纹的动画效果,我之前测试机一直是4.1系统的,一切正常。今天无意间用一个4.0.3的手机跑了一下,发现setDuration失效了。然后我又拿了一台4.0.2系统的手机测,发现依旧失效,然后将代码改为:
animatorSet = new AnimatorSet();
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorList = new ArrayList<Animator>();
for (int i = 0; i < rippleAmount; i++) {
RippleView rippleView = new RippleView(getContext());
addView(rippleView, rippleParams);
rippleViewList.add(rippleView);
final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleXAnimator.setStartDelay(i * rippleDelay);
scaleXAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleXAnimator);
final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleYAnimator.setStartDelay(i * rippleDelay);
scaleYAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleYAnimator);
final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
alphaAnimator.setStartDelay(i * rippleDelay);
alphaAnimator.setDuration(rippleDurationTime);
animatorList.add(alphaAnimator);
}
animatorSet.playTogether(animatorList);
就正常了。其实就是把Duration在每个动画里set一下,其实具体我还没搞清楚为什么在4.0.x上用animatorSet去设置Duration无效的原因,希望能和大家讨论一下。
animatorSet = new AnimatorSet();
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.setDuration(rippleDurationTime);
animatorList = new ArrayList<Animator>();
for (int i = 0; i < rippleAmount; i++) {
RippleView rippleView = new RippleView(getContext());
addView(rippleView, rippleParams);
rippleViewList.add(rippleView);
final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleXAnimator.setStartDelay(i * rippleDelay);
animatorList.add(scaleXAnimator);
final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleYAnimator.setStartDelay(i * rippleDelay);
animatorList.add(scaleYAnimator);
final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
alphaAnimator.setStartDelay(i * rippleDelay);
animatorList.add(alphaAnimator);
}
animatorSet.playTogether(animatorList);这是那个波纹的动画效果,我之前测试机一直是4.1系统的,一切正常。今天无意间用一个4.0.3的手机跑了一下,发现setDuration失效了。然后我又拿了一台4.0.2系统的手机测,发现依旧失效,然后将代码改为:
animatorSet = new AnimatorSet();
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorList = new ArrayList<Animator>();
for (int i = 0; i < rippleAmount; i++) {
RippleView rippleView = new RippleView(getContext());
addView(rippleView, rippleParams);
rippleViewList.add(rippleView);
final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleXAnimator.setStartDelay(i * rippleDelay);
scaleXAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleXAnimator);
final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleYAnimator.setStartDelay(i * rippleDelay);
scaleYAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleYAnimator);
final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
alphaAnimator.setStartDelay(i * rippleDelay);
alphaAnimator.setDuration(rippleDurationTime);
animatorList.add(alphaAnimator);
}
animatorSet.playTogether(animatorList);
就正常了。其实就是把Duration在每个动画里set一下,其实具体我还没搞清楚为什么在4.0.x上用animatorSet去设置Duration无效的原因,希望能和大家讨论一下。
相关文章推荐
- android 4.0.x上AnimatorSet.setDuration上的坑
- ArcIMS中对FeatureLayer 设置setMaxScale()和setMinScale()注意问题!
- mysql中的 IN和FIND_IN_SET的查询问题
- JS正则替换问题 http://bbs.51js.com/redirect.php?fid=1&tid=67418&goto=nextnewset
- JSP使用get/setProperty时,Bean的scope 改变引起的问题
- CRM中Customer遇到的Set属性排序问题
- 一句set nocount on解决问题
- 学习中遇到的问题-关于set_new_handler()
- SET NOCOUNT 的怪问题
- IIS的缓存问题最终解决方案, Fucking The Default IIS Cache SET
- 关于SET COUNT ON 和 @@ROWCOUNT的问题
- SetStretchBltMode函数的问题
- Set中元素的问题
- 很怪异的asp问题,set rs=server.createobject("adodb.recordset")和set rs=conn.execute(sql)的区别
- 有关set的是否变的问题
- 使用hibernate心得——字符串超长的解决办法(setCharacterStream出现顺序问题)
- Paging of Large Resultsets in ASP.NET中介绍的SET ROWCOUNT方式存储过程的问题
- NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题)
- Java中Set包含重复元素的问题
- JDBC 的 setTimestamp 性能问题