【问题标题】:Android- setDuration not Working? ObjectAnimatorAndroid-setDuration 不起作用?对象动画师
【发布时间】:2019-05-26 15:54:25
【问题描述】:

我正在尝试使用 ObjectAnimator 将 ImageView 向下移动。 setDuration() 方法似乎不会影响动画的持续时间。我无法在 XML 中设置此动画,因为我想动态播放它。

    ObjectAnimator an= ObjectAnimator.ofFloat(img, View.TRANSLATION_Y, 0, 100);
    an.setDuration(5000);
    an.start();

这里有点离题,但是说我想一个接一个地玩多个 ObjectAnimation,有没有办法做到这一点?我查看了 Animator 集,但不确定它是否会像 Object Animator 一样移动实际对象,而不是像在 TranslateAnimation 中那样出现。

提前致谢!

【问题讨论】:

  • 请创建一个MCVE。对于顺序动画,请查看AnimatorSet
  • 好吧,我已经尽力了。

标签: android animation


【解决方案1】:

也许您正在三星设备上进行测试?在这种情况下,在开发人员选项下有一个选项 Animator duration scale 默认设置为关闭。如果切换到正常值,您可以看到动画。

希望对您有所帮助。

【讨论】:

  • 否,但我禁用了 Animator Duration Scale。现在可以了,谢谢帮助。现在有没有办法让我不受 Animator Duration Scale 影响的动画视图?
  • 所以,基本上,如果我确实使用 animator.setDuration 向我的应用程序添加了动画,并且有人禁用了动画师持续时间比例,那么他会看到,事情进展得很快吗?
【解决方案2】:

LayoutInflater 充气机 = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View popupView = inflater.inflate(R.layout.loading_popup, null,false);
    popup = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
    popup.setContentView(popupView);
    popup.setOutsideTouchable(true);
    ImageView loadingPlane=(ImageView)popupView.findViewById(R.id.loading_plane);

    RotateAnimation anim = new RotateAnimation(0.0f, 360.0f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f);
    // Step 2:  Set the Animation properties
    anim.setInterpolator(new LinearInterpolator());
    //anim.setRepeatCount(Animation.INFINITE);

    anim.setRepeatCount(-1);
    anim.setDuration(1500);
    loadingPlane.startAnimation(anim);

    findViewById(R.id.flyinstyle).post(new Runnable() {
        public void run() {
            popup.showAtLocation(findViewById(R.id.flyinstyle), Gravity.CENTER, 0, 0);
        }
    });

【讨论】:

    猜你喜欢
    • 2021-10-18
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    相关资源
    最近更新 更多