Androids ObjectAnimator.ofFloat无法正常工作

Ben*_*mer 11 animation android android-animation

我在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, "alpha", 0f, 1f);
    fadeIn.setDuration(2000);

    AnimatorSet animatorSet = new AnimatorSet();

    animatorSet.play(mover).with(fadeIn).after(fadeOut);
    animatorSet.start();
}
Run Code Online (Sandbox Code Playgroud)

三星Galaxy S4(Android 4.4.2):

    getInterpolation() 1,0000
    getInterpolation() 1,0000
Run Code Online (Sandbox Code Playgroud)

三星Galaxy S5(Android 4.4.2):

    getInterpolation() 0,0000
    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
Run Code Online (Sandbox Code Playgroud)

有谁有想法,为什么这不能正常工作?

Mik*_*ter 21

在Galaxy S4上,在Developer Options下,有Animator持续时间刻度选项.出于某些原因,默认情况下这是关闭的.将此切换为1x后,我在S4上的动画开始完美运行.这可能是导致您的问题的原因.

  • 我的设置为 1x,我仍然看到这个问题。 (2认同)