【问题标题】:Android Flip animation rotation pointAndroid Flip动画旋转点
【发布时间】:2013-09-05 18:08:51
【问题描述】:

大家好,我已经按照 android 翻转动画教程为图像制作动画,但是我遇到了这个问题,我尝试像在应用程序 ibutterfly 中那样为蝴蝶制作动画,并且我正在使用这种方法来应用转换

protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees
            + ((mToDegrees - fromDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();

    camera.rotateY(degrees);



    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);

    matrix.preScale(scaleType.getScale(scale, interpolatedTime),
            scaleType.getScale(scale, interpolatedTime), centerX, centerY);

}

我遇到的问题是图像从中间点旋转但我需要将旋转轴更改为左角有没有办法做到这一点,我尝试了我所知道的一切但我无法做到,如果有人可以的话帮我解决这个问题,我将不胜感激

这是我在 Google Code 上遵循的教程。

【问题讨论】:

  • 你试过this库吗?
  • 在有一种方法可以定义旋转轴,它只能围绕中间旋转,不能改变它,我不知道可能是我错了,但我认为这个库没有帮助thanx答案:)
  • 好吧,您将不得不探索代码并进行一些更改,但我认为该库是您需要的最接近的库。花时间使用它,您肯定可以修改它。我会尝试,但因为我忙于我的项目,所以我必须在周末做。所以,祝你好运!
  • 好的,谢谢,我会调查的,非常感谢您的帮助
  • 很高兴为您提供帮助,希望您一切顺利。让我知道你是否能够破解它!

标签: android android-animation


【解决方案1】:

终于找到了改变旋转轴的方法。问题是我在看上面的方法不是改变旋转轴的地方只需要改变下面的方法

public static Animation[] flipAnimation(
            final View fromView,
            final View toView,
            FlipDirection flipDirection,
            long duration, Interpolator interpolator) {
        Animation[] result = new Animation[2];
        float centerX;
        float centerY;

        centerX = 0.0f; // Simpliy had to change the centerX value here 
        centerY = fromView.getHeight(); 

        Animation outFlip = new FlipAnimation(
                flipDirection.getStartDegreeForFirstView(),
                flipDirection.getEndDegreeForFirstView(), centerX, centerY,
                FlipAnimation.SCALE_DEFAULT,
                FlipAnimation.ScaleUpDownEnum.SCALE_NONE);
        outFlip.setDuration(duration);
        outFlip.setFillAfter(true);
        outFlip.setInterpolator(interpolator == null ? new AccelerateInterpolator()
                : interpolator);

        AnimationSet outAnimation = new AnimationSet(true);
        outAnimation.addAnimation(outFlip);
        result[0] = outAnimation;

        // Uncomment the following if toView has its layout established (not the
        // case if using ViewFlipper and on first show)
        // centerX = toView.getWidth() / 2.0f;
        // centerY = toView.getHeight() / 2.0f;

        Animation inFlip = new FlipAnimation(
                flipDirection.getStartDegreeForSecondView(),
                flipDirection.getEndDegreeForSecondView(), centerX, centerY,
                FlipAnimation.SCALE_DEFAULT,
                FlipAnimation.ScaleUpDownEnum.SCALE_NONE);
        inFlip.setDuration(duration);
        inFlip.setFillAfter(true);
        inFlip.setInterpolator(interpolator == null ? new AccelerateInterpolator()
                : interpolator);
        inFlip.setStartOffset(duration);

        AnimationSet inAnimation = new AnimationSet(true);
        inAnimation.addAnimation(inFlip);
        result[1] = inAnimation;

        return result;

    }

【讨论】:

    猜你喜欢
    • 2012-12-16
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多