【问题标题】:Android rotation does not work in ObjectAnimatorAndroid 旋转在 ObjectAnimator 中不起作用
【发布时间】:2015-09-14 23:59:41
【问题描述】:

我使用 Animator XML 为 ImageView 设置动画。 ImageView 应该增长(从 0f 到 1f,Y 比 X 快)并且从 90 到 0 旋转 90°。 我将这个 XML 文件用于动画:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:ordering="together">
    <objectAnimator
        android:duration="500"
        android:propertyName="scaleY"
        android:valueFrom="0f"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:valueTo="1f"
        android:valueType="floatType" />

    <objectAnimator
        android:duration="1000"
        android:propertyName="scaleX"
        android:valueFrom="0f"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:valueTo="1f"
        android:valueType="floatType" />

    <objectAnimator
        android:duration="1000"
        android:transformPivotX="0dp"
        android:transformPivotY="0dp"
        android:interpolator="@android:anim/linear_interpolator"
        android:propertyName="rotate"
        android:valueFrom="90"
        android:valueType="floatType"
        android:valueTo="0" />

</set>

当我应用 Animator 时

AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this,
                R.animator.login_bubble_animation);
        set.setTarget(mContactBubble);
        set.start();

除了旋转之外的一切都有效,所以 ImageView 增长但不旋转。我已经用过

RotateAnimation rotate = new RotateAnimation(90, 0, Animation.RELATIVE_TO_SELF,
            0.5f,  Animation.RELATIVE_TO_SELF, 0.5f);
    rotate.setDuration(1000);
    mContactBubble.startAnimation(rotate);

这确实有效,但如果它位于 XML 文件中,那将是一个优势。

【问题讨论】:

  • android:propertyName="rotationX" 或 rotationY
  • @mt0s 这确实有效,但我想绕 z 轴旋转。

标签: android android-animation objectanimator


【解决方案1】:

您的属性字符串名称rotate 无效。您需要使用rotation,或者rotationX 和/或rotationY,就像您为规模所做的那样。 http://developer.android.com/guide/topics/graphics/prop-animation.html#views 获取与 ObjectAnimator 一起使用的属性列表

【讨论】:

  • 工作,谢谢。有趣的是,即使经过 5 年的编码,如此小的错误也会让你感到绝望。
【解决方案2】:

您使用了错误命名的属性:rotate。应该是rotation

视图类必须具有该属性的 setter 和 getter 才能作为属性使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2013-01-17
    相关资源
    最近更新 更多