派生Animation,新建了一个动画类,在applyTransformation方法里用android.graphics.Camera旋转一个角度。这个动画类放在View里很正常,用View.startAnimation(Animation),
但是用Activity.overridePendingTransition(int, int),旋转的时候好像旋转轴变了。同样的代码,为什么效果不一样?

解决方案 »

  1.   


    package com.xxx.animation;import android.content.Context;
    import android.content.res.TypedArray;
    import android.graphics.Camera;
    import android.graphics.Matrix;
    import android.util.AttributeSet;
    import android.view.animation.Animation;
    import android.view.animation.Transformation;public class FakeRotateXAnimation extends Animation
    {
    private final int mPivotYType;
    private final float mPivotYValue; private float mPivotY = 0.0f; private final float mFromDegrees;
    private final float mToDegrees; private float mSemiWidth = 0.0f; private final Camera mCamera;// public FakeRotateXAnimation(Context context, AttributeSet attrs)
    // {
    // super(context, attrs);
    //
    // TypedArray a = context.obtainStyledAttributes(attrs,
    //                com.android.internal.R.styleable.FakeRotateXAnimation);
    //
    //        mFromDegrees = a.getFloat(
    //                com.android.internal.R.styleable.FakeRotateXAnimation_fromDegrees, 0.0f);
    //        mToDegrees = a.getFloat(com.android.internal.R.styleable.FakeRotateXAnimation_toDegrees, 0.0f);
    //
    //        Description d = Description.parseValue(a.peekValue(
    //            com.android.internal.R.styleable.FakeRotateXAnimation_pivotY));
    //        mPivotYType = d.type;
    //        mPivotYValue = d.value;
    //
    //        a.recycle();
    //
    // mCamera = new Camera();
    // } public FakeRotateXAnimation(float fromDegrees, float toDegrees, float pivotY)
    {
    this(fromDegrees, toDegrees, ABSOLUTE, pivotY);
    } public FakeRotateXAnimation(float fromDegrees, float toDegrees,
    int pivotYType, float pivotYValue)
    {
    this.mFromDegrees = fromDegrees;
    this.mToDegrees = toDegrees; this.mPivotYType = pivotYType;
    this.mPivotYValue = pivotYValue; mCamera = new Camera();
    } @Override
    protected void applyTransformation(float interpolatedTime, Transformation t)
    {
    final float fromDegrees = mFromDegrees;
    final float pivotY = mPivotY;
    final float semiWidth = mSemiWidth;
    final Camera camera = mCamera; final Matrix matrix = t.getMatrix();
    final float degrees = fromDegrees + (mToDegrees - fromDegrees)
    * interpolatedTime; camera.save();
    camera.rotateX(degrees);
    camera.getMatrix(matrix);
    camera.restore(); matrix.preTranslate(-semiWidth, -pivotY);
    matrix.postTranslate(semiWidth, pivotY);
    } @Override
    public void initialize(int width, int height, int parentWidth,
    int parentHeight)
    {
    super.initialize(width, height, parentWidth, parentHeight); this.mPivotY = this.resolveSize(mPivotYType, mPivotYValue, height,
    parentHeight);
    this.mSemiWidth = width / 2;
    }
    }这个动画,给view显示地很完美,直接给activity就一塌糊涂,到底为什么?
      

  2.   

    调试了,都一样,但是matrix里面的值不知道怎么看
      

  3.   

    会不会有权限的问题呢,我曾经遇到过在APK里可以用,但是直接嵌入Android系统中,却不能调用的API函数,最后屏蔽了权限才可以跑,在执行之前都有权限的检查。
      

  4.   

    我觉得不是什么权限的问题!
    overridePendingTransition它本身是针对整个Activity的,而View.startAnimation是只是针对这个view的,使用overridePendingTransition让其旋转,它可能找不到其中心点,所以比较乱!
    其实,我也在纠结中...