开发者

Why is my rotate animation all wonky when applied to an Activity transition?

What is the below animation supposed to do?

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

Easy enough. It should represent a clockwise rotation about the centre. Just spin around once, then stop. Right?

And so it does... when I apply it to a View.

But when I animate an activity transition instead, something entirely different happens. The activity starts to rotate counterclockwise, but at the same time it flies off the top right of the screen. Then it comes back, still rotating counterclockwise and by now upside-down, and flies off the bottom left of the screen. Finally, it comes back and ends its rotation upright.

No matter what I specify for pivotX and pivotY, the behaviour is always the same. They seem 开发者_如何学Cto be ignored completely. And either way, the thing is certainly not rotating around any fixed pivot at all!

What kind of nonsense is this? Is it a bug?

For completeness, I saved this animation as res/anim/spin.xml, and invoke it as follows:

startActivity(intent);
overridePendingTransition(R.anim.spin, R.anim.spin);

(Using the same animation for both in and out makes no sense, but this is the minimal example.)


Update: Demo app to reproduce this issue

I've put together a minimal Android project that demonstrates the problem. The main activity looks like this:

package com.example.animtest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

public class MainActivity extends Activity {

    private View rootView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rootView = getLayoutInflater().inflate(R.layout.main, null);
        setContentView(rootView);
    }

    public void animateRootView(View view) {
        Animation spin = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.spin);
        rootView.setAnimation(spin);
        spin.start();
    }

    public void animateActivity(View view) {
        Intent intent = new Intent();
        intent.setClassName("com.example.animtest", "com.example.animtest.MainActivity");
        startActivity(intent);
        overridePendingTransition(R.anim.spin, R.anim.spin);
    }

}

Here are the ZIP file with the project source and the runnable APK file. Tested on Nexus One, Android 2.2.2.


known issue .. till 2.3.4 nothing has been done :( http://code.google.com/p/android/issues/detail?id=10402


Sounds like we don't quite support rotation animations on Activities :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜