Reputation: 3
i am trying to scale an image, rotate it, rotate it backwards and then scale it to its origninal size.
This is allready working, but i cant figure out how to repeat this animation set infinitly ( android:repeatCount="infinite"
isnt working for me ).
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:shareInterpolator="true"
android:repeatCount="infinite"
>
<scale
android:fromXScale="1.0"
android:toXScale="4.0"
android:fromYScale="1.0"
android:toYScale="4.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="700"
/>
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:duration="2000"
/>
<rotate
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="2700"
android:duration="2000"
/>
<scale
android:fromXScale="1.0"
android:toXScale="0.25"
android:fromYScale="1.0"
android:toYScale="0.25"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="4700"
android:duration="700"
/>
</set>
and in the Activity:
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
Animation rotateAndScale = AnimationUtils.loadAnimation(this, R.anim.rotate_z);
imageView.startAnimation(rotateAndScale);
Upvotes: 0
Views: 835
Reputation: 36
<set>
marker in xml is bad implemented and not work propperly. Full explenation here: Android animation does not repeat
what you should do is use listener and method to use recurency to roll the anim for ever.
public void startAnimation() {
View component= findViewById(R.id.imageView2);
component.setVisibility(View.VISIBLE);
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate_z);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate_z);
anim.setAnimationListener(this);
component.startAnimation(anim);
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
});
component.startAnimation(anim);
}
Upvotes: 1