10

有人知道Android动画吗?我想创建如下内容:

  • 我的设备屏幕中央有一个大图像;
  • 该图像变小(通过动画)并转到我的设备屏幕的一角;

它类似于以下顺序:

在此处输入图像描述

任何提示将不胜感激!提前致谢!

4

2 回答 2

8

ViewPropertyAnimator, 与 和 之类的方法一起scaleXBy()使用translateYBy()。您可以ViewPropertyAnimator通过调用API 级别 11+animate()上的, 来获得 a 。View如果您支持较旧的设备,NineOldAndroids提供了一个类似工作的后端。

您可能还希望阅读:

于 2012-09-10T18:24:27.063 回答
7

我有一堂同时旋转和运动的课。它的成本很高,但它适用于所有 API 版本。

public class ResizeMoveAnimation extends Animation {
    View view; 
    int fromLeft; 
    int fromTop; 
    int fromRight;
    int fromBottom;
    int toLeft; 
    int toTop; 
    int toRight;
    int toBottom;

    public ResizeMoveAnimation(View v, int toLeft, int toTop, int toRight, int toBottom) {
        this.view = v;
        this.toLeft = toLeft;
        this.toTop = toTop;
        this.toRight = toRight;
        this.toBottom = toBottom;

        fromLeft = v.getLeft();
        fromTop = v.getTop();
        fromRight = v.getRight();
        fromBottom = v.getBottom();

        setDuration(500);
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {

        float left = fromLeft + (toLeft - fromLeft) * interpolatedTime;
        float top = fromTop + (toTop - fromTop) * interpolatedTime;
        float right = fromRight + (toRight - fromRight) * interpolatedTime;
        float bottom = fromBottom + (toBottom - fromBottom) * interpolatedTime;

        RelativeLayout.LayoutParams p = (LayoutParams) view.getLayoutParams();
        p.leftMargin = (int) left;
        p.topMargin = (int) top;
        p.width = (int) ((right - left) + 1);
        p.height = (int) ((bottom - top) + 1);

        view.requestLayout();
    }
}
于 2013-01-21T23:10:54.370 回答