I use an Animator XML to animate an ImageView. The ImageView should grow (from 0f to 1f, Y faster than X) and rotate 90° from 90 to 0. I use this XML file for the animation:
<?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>
When I apply the Animator with
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this,
R.animator.login_bubble_animation);
set.setTarget(mContactBubble);
set.start();
everything except the rotation works, so the ImageView grows but does not rotate. I already used
RotateAnimation rotate = new RotateAnimation(90, 0, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(1000);
mContactBubble.startAnimation(rotate);
which does work but it would an advantage if it is inside the XML file.
答案 0 :(得分:5)
your property string name rotate
is not valid. You need to use rotation
, or else rotationX
and/or rotationY
, just like you did for scale. http://developer.android.com/guide/topics/graphics/prop-animation.html#views for a list of properties that work with ObjectAnimator
答案 1 :(得分:3)
You're using an incorrectly named property: rotate
. It should be rotation
.
The view class must have setters and getters for that attribute for it to be available as a property.