0

This is my xml for rotating the TextView:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fillAfter="true"
    android:fromDegrees="0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="180" />

When I press on the button 'Rotate', the TextView will rotate normally, after rotation it will appear flipped vertically as the rotation angle is 180.

The problem is when I press on the button again to rotate it for another 180 degrees, it returns to its original state before rotation.

I want it to rotate from its last state.

Hamzeh Soboh
  • 7,572
  • 5
  • 43
  • 54

3 Answers3

0

Check out this SO answer. I think the attributes you need are:

fillAfter=true
fillEnabled=true

How can I animate a view in Android and have it stay in the new position/size?

Community
  • 1
  • 1
frenziedherring
  • 2,225
  • 2
  • 15
  • 23
  • 1
    I don't think the second animation will continue the rotation. I'm afraid 2 animations are needed, one from 0 to 180 degrees, second for the next half turn. Calling `View.startAnimation()` resets the previous transformation. – Code Painters Oct 10 '12 at 12:22
0

you should create more xml files..but best option would be to do this grammatically, i am sure it will work.

jay
  • 292
  • 1
  • 11
0

Thanks for your replies, now I can say:

int x = 0, y = 180; // global variables

Then:

        RotateAnimation a = new RotateAnimation(x, y,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        a.setFillEnabled(true);
        a.setFillAfter(true);
        a.setDuration(1000);
        a.setAnimationListener(onRotation);
        txtView.startAnimation(a);

Then:

AnimationListener onRotation = new AnimationListener() {

    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }

    public void onAnimationEnd(Animation animation) {
        x += 180;
        y += 180;

    }
};
Hamzeh Soboh
  • 7,572
  • 5
  • 43
  • 54