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

10

有人了解Android动画吗?我想创建以下内容:

  • 我在设备屏幕中心有一张大图片;
  • 通过动画,该图片变小并移到设备屏幕的角落。

就像下面这个序列中的演示:

输入图片描述

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

2个回答

8

感谢CommonsWare。毫无疑问,这非常有帮助! - Marcelo

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();
    }
}

我们如何使用所提到的视图调用此调整大小动画? - shobhan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接