如何在Android中创建移动/调整大小的动画?

Mar*_*elo 10 animation android

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

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

它的类似于下面的序列:

在此输入图像描述

任何提示都将非常感谢!提前致谢!

Com*_*are 8

使用ViewPropertyAnimator,用类似的方法scaleXBy()translateYBy().你得到一个ViewPropertyAnimator通过调用animate()View,在API级别11+.如果您支持较旧的设备,NineOldAndroids提供近乎相同的后端口.

您可能还希望阅读:


Ado*_*ncz 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();
    }
}
Run Code Online (Sandbox Code Playgroud)