微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android的ObjectAnimator.ofFloat无法正常工作

我在一个 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上的动画开始工作得很好.这可能是导致您的问题的原因.

原文地址:https://www.jb51.cc/android/312421.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐