android的动画问题与ios比较

问题描述:

那么,对于初学者来说,我认为我最大的问题是假设或希望android动画行为像ios。android的动画问题与ios比较

我有一个时间指示器,每100毫秒更新一次,我希望你随着时间流逝移动他们在x中的位置。

IOS代码:

[NSTimer scheduledTimerWithTimeInterval:.1f target:self selector:@selector(moveIndicator:) userInfo:nil repeats:YES]; 

和内部moveIndicator功能。

[UIView animateWithDuration:.1f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{ 

    _playIndicatorView.frame = CGRectMake(myXpos, _playIndicatorView.frame.origin.y, _playIndicatorView.frame.size.width, _playIndicatorView.frame.size.height); 

} completion:^(BOOL finished) { 
}]; 

,这看起来像:

enter image description here

我试图做到这一点在Android和我期待的动画不表现

的Android代码:

For Init .1f计时器。

private Runnable runnable = new Runnable() { 
     public void run() { 
      if (!killMoveIndicatorTimer) { 
       moveIndicator(); 
       handler.postDelayed(this, 100); 
      } 
     } 
    }; 

对于呼叫runnable我使用:

handler = new Handler(); 
runnable.run(); 

对于招我使用的指标:

ObjectAnimator anim = ObjectAnimator.ofFloat(playerIndicatorView, "translationX", myXpos); 
anim.setDuration(100); 
anim.start(); 

,看起来像:

enter image description here

和这个其他选项也:

playerIndicatorView.animate().x(myXpos); 

的样子:

enter image description here

我绝对相信必有b e以某种方式使此动画尽可能与ios类似。

谢谢你的时间。

+0

如果我猜的话,你的问题是不是与动画,但是,你正在做的是占用主应用程序线程等工作。 – CommonsWare

你应该使用:

ObjectAnimator anim = ObjectAnimator.ofFloat(playerIndicatorView, "translationX", backgroundStripe.getWidth()); 
anim.setDuration(3000); 
anim.start(); 

与你的第一个例子的主要问题是与handler.postDelayed(this, 100);您的动画具有持续时间100毫秒,而建成后的处理程序将100毫秒后执行下一个动画。

对于第二个例子你不使用LinearInterpolator:

ViewPropertyAnimator viewPropertyAnimator = playerIndicatorView.animate(); 
viewPropertyAnimator.setInterpolator(new LinearInterpolator()); 
viewPropertyAnimator.setDuration(2000); 
viewPropertyAnimator.translationX(backgroundStripe.getWidth());