0

这是我用于旋转 TextView 的 xml:

<?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" />

当我按下“旋转”按钮时,TextView 将正常旋转,旋转后它会出现垂直翻转,因为旋转角度为 180。

问题是当我再次按下按钮将其再旋转 180 度时,它会恢复到旋转前的原始状态。

我希望它从最后一个状态旋转。

4

3 回答 3

0

看看这个 SO 答案。我认为您需要的属性是:

fillAfter=true
fillEnabled=true

如何在 Android 中为视图设置动画并使其保持在新的位置/大小?

于 2012-10-10T12:17:42.507 回答
0

你应该创建更多的 xml 文件。但最好的选择是在语法上这样做,我相信它会起作用。

于 2012-10-10T12:32:28.633 回答
0

感谢您的回复,现在我可以说:

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

然后:

        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);

然后:

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;

    }
};
于 2012-10-10T13:43:52.910 回答