Android的ObjectAnimator.ofFloat无法正常工作

前端之家收集整理的这篇文章主要介绍了Android的ObjectAnimator.ofFloat无法正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在一个 Android应用程序中使用了ObjectAnimator.ofFloat,它不会在每个设备上都以同样的方式工作.

MainActivity(扩展活动):

  1. Button button1 = (Button) findViewById(R.id.button1);
  2. button1.setOnClickListener(new View.OnClickListener() {
  3. @Override
  4. public void onClick(View v) {
  5. startAnimation();
  6. }
  7. });
  8.  
  9.  
  10. public void startAnimation() {
  11. ImageView aniView = (ImageView) findViewById(R.id.imageView1);
  12. ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView,"alpha",0f);
  13. fadeOut.setDuration(2000);
  14.  
  15. ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,"translationX",-500f,0f);
  16. mover.setInterpolator(new TimeInterpolator() {
  17. @Override
  18. public float getInterpolation(float input) {
  19. Log.v("MainActivity","getInterpolation() " + String.format("%.4f",input));
  20. return input;
  21. }
  22. });
  23. mover.setDuration(2000);
  24.  
  25. ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView,0f,1f);
  26. fadeIn.setDuration(2000);
  27.  
  28. AnimatorSet animatorSet = new AnimatorSet();
  29.  
  30. animatorSet.play(mover).with(fadeIn).after(fadeOut);
  31. animatorSet.start();
  32. }

三星Galaxy S4(Android 4.4.2):

  1. getInterpolation() 1,0000
  2. getInterpolation() 1,0000

三星Galaxy S5(Android 4.4.2):

  1. getInterpolation() 0,0000
  2. getInterpolation() 0,0085
  3. getInterpolation() 0,0170
  4. getInterpolation() 0,0255
  5. ...
  6. ...
  7. getInterpolation() 0,9740
  8. getInterpolation() 0,9825
  9. getInterpolation() 0,9910
  10. getInterpolation() 0,9995
  11. getInterpolation() 1,0000

有人有一个想法,为什么这不能正常工作?

解决方法

在Galaxy S4上,在“开发人员选项”下,有“动画师持续时间”选项.由于一些野蛮的原因,这是默认关闭.将其切换到1x后,我在S4上的动画开始工作得很好.这可能是导致您的问题的原因.

猜你在找的Android相关文章