如何对角的图像转换动画? [英] How to translate animation on an image diagonally?

查看:208
本文介绍了如何对角的图像转换动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动画图像对角线像下面的图片。我曾尝试翻译的动画,但我只能够做到这一点无论是平行X轴平行或Y轴。

I want to animate an image diagonally like below picture. I have tried translate animation but I am only able to do it either parallel X-axis or parallel Y-axis.

但无法能够弄清楚如何做到这一点对角。而且我也不能肯定它可以被翻译动画或其他一些还挺动画来完成。所以,请建议我我该怎么做,或如果任何人可以给我一个有用的链接,那么我也将obiliged。

But couldn't able to figure out how to do it diagonally. And I am also not sure it can be done by translate animation or some other kinda animation. So please suggest me how can I do it or if any one can give me a helpful link then also I will be obiliged.

推荐答案

一种方法是使用 AnimatorSet 多玩 ObjectAnimator 在一起。

One way is to use an AnimatorSet to play more ObjectAnimator together.

private void animateDiagonalPan(View v) {
    AnimatorSet animSetXY = new AnimatorSet();

    ObjectAnimator y = ObjectAnimator.ofFloat(v,
                "translationY",v.getY(), targetY);

    ObjectAnimator x = ObjectAnimator.ofFloat(v,
                "translationX", v.getX(), targetX);

    animSetXY.playTogether(x, y);
    animSetXY.setInterpolator(new LinearInterpolator(1f));
    animSetXY.setDuration(300);
    animSetXY.start();
}

或者你可以使用自定义的查看使用自定义的属性,但在这种情况下,你需要计算翻译在X和Y自己:

Or you could use a custom View with a custom Property, but in this case you will need to compute translation on X and Y yourself:

final Property<YourView, Float> transProperty = new Property<YourView, Float>(
        float.class, "translation") {
    @Override
    public Float get(YourView) {
        return object.getTranslation();
    }

    @Override
    public void set(YourView, Float value) {
        object.translate(value);
    }
};

private void translate(float value){
       setTranslationX(value);
       setTranslationY(value);
}

和使用它来制作动画:

private void animateDiagonalPan(View v) {

    ObjectAnimator xy = ObjectAnimator.ofFloat(v,
                transProperty, targetValue);

    xy.setInterpolator(new LinearInterpolator(1f));
    xy.setDuration(300);
    xy.start();
}

这篇关于如何对角的图像转换动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆