我在一个
Android应用程序中使用了ObjectAnimator.ofFloat,它不会在每个设备上都以同样的方式工作.
MainActivity(扩展活动):
- Button button1 = (Button) findViewById(R.id.button1);
- button1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- startAnimation();
- }
- });
- public void startAnimation() {
- ImageView aniView = (ImageView) findViewById(R.id.imageView1);
- ObjectAnimator fadeOut = ObjectAnimator.ofFloat(aniView,"alpha",0f);
- fadeOut.setDuration(2000);
- ObjectAnimator mover = ObjectAnimator.ofFloat(aniView,"translationX",-500f,0f);
- mover.setInterpolator(new TimeInterpolator() {
- @Override
- public float getInterpolation(float input) {
- Log.v("MainActivity","getInterpolation() " + String.format("%.4f",input));
- return input;
- }
- });
- mover.setDuration(2000);
- ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView,0f,1f);
- fadeIn.setDuration(2000);
- AnimatorSet animatorSet = new AnimatorSet();
- animatorSet.play(mover).with(fadeIn).after(fadeOut);
- animatorSet.start();
- }
三星Galaxy S4(Android 4.4.2):
- getInterpolation() 1,0000
- getInterpolation() 1,0000
三星Galaxy S5(Android 4.4.2):
- getInterpolation() 0,0000
- getInterpolation() 0,0085
- getInterpolation() 0,0170
- getInterpolation() 0,0255
- ...
- ...
- getInterpolation() 0,9740
- getInterpolation() 0,9825
- getInterpolation() 0,9910
- getInterpolation() 0,9995
- getInterpolation() 1,0000
有人有一个想法,为什么这不能正常工作?
解决方法
在Galaxy S4上,在“开发人员选项”下,有“动画师持续时间”选项.由于一些野蛮的原因,这是默认关闭.将其切换到1x后,我在S4上的动画开始工作得很好.这可能是导致您的问题的原因.