安卓图片动画移动

1、直线运动:
1、多个同步 、异步、顺序执行

ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView,
                "translationX", 0F, 360F);// X轴平移旋转

        ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView,
                "translationY", 0F, 300F);// Y轴平移旋转

        ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,
                "rotation", 0F, 360F);// 360度旋转

        AnimatorSet set = new AnimatorSet();

        // set.playSequentially(animator1, animator2, animator3);// 分步执行

        set.playTogether(animator1, animator2, animator3);// 同步执行

        // 属性动画的执行顺序控制

        // 先同步执行动画animator2和animator3,然后再执行animator1

        /*
         * set.play(animator3).with(animator1);
         * 
         * set.play(animator2).after(animator3);
         */

        set.setDuration(1000);

        set.start();

2、抛物线运动:

// 分300步进行移动动画
    final int count = 150;

    /**
     * 要start 动画的那张图片的ImageView--------------------(二)抛物线运动
     * 
     * @param imageView
     */
    private void startAnimation(final ImageView imageView) {

        Keyframe[] keyframes = new Keyframe[count];
        final float keyStep = 1f / (float) count;
        float key = keyStep;
        for (int i = 0; i < count; ++i) {
            keyframes[i] = Keyframe.ofFloat(key, i + 1);
            key += keyStep;
        }

        PropertyValuesHolder pvhX = PropertyValuesHolder.ofKeyframe(
                "translationX", keyframes);
        key = keyStep;
        for (int i = 0; i < count; ++i) {
            keyframes[i] = Keyframe.ofFloat(key, -getY(i + 1));
            key += keyStep;
        }

        PropertyValuesHolder pvhY = PropertyValuesHolder.ofKeyframe(
                "translationY", keyframes);
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,
                "rotation", 0F, 360F);// 360度旋转
        ObjectAnimator yxBouncer = ObjectAnimator.ofPropertyValuesHolder(imageView, pvhY, pvhX).setDuration(1500);
        yxBouncer.setInterpolator(new BounceInterpolator());
        AnimatorSet set = new AnimatorSet();

        // set.playSequentially(animator1, animator2, animator3);// 分步执行

        set.playTogether(yxBouncer, animator3);// 同步执行
        set.setDuration(1000);
        set.start();
    }

    final float a = -1f / 105f;

    /**
     * 这里是根据三个坐标点{(0,0),(300,0),(150,300)}计算出来的抛物线方程
     * 
     * @param x
     * @return
     */
    private float getY(float x) {
        return a * x * x + 4 * x;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值