zoukankan      html  css  js  c++  java
  • Keyframe类-动画中关键帧概念

    package com.loaderman.customviewdemo;
    
    import android.animation.Animator;
    import android.animation.Keyframe;
    import android.animation.ObjectAnimator;
    import android.animation.PropertyValuesHolder;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.ImageView;
    
    public class MainActivity extends AppCompatActivity {
        ImageView mImg;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mImg = (ImageView) findViewById(R.id.img);
    
            findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
    
                    /**
                     * 左右震动效果
                     */
                    Keyframe frame0 = Keyframe.ofFloat(0f, 0);
                    Keyframe frame1 = Keyframe.ofFloat(0.1f, -20f);
                    Keyframe frame2 = Keyframe.ofFloat(0.2f, 20f);
                    Keyframe frame3 = Keyframe.ofFloat(0.3f, -20f);
                    Keyframe frame4 = Keyframe.ofFloat(0.4f, 20f);
                    Keyframe frame5 = Keyframe.ofFloat(0.5f, -20f);
                    Keyframe frame6 = Keyframe.ofFloat(0.6f, 20f);
                    Keyframe frame7 = Keyframe.ofFloat(0.7f, -20f);
                    Keyframe frame8 = Keyframe.ofFloat(0.8f, 20f);
                    Keyframe frame9 = Keyframe.ofFloat(0.9f, -20f);
                    Keyframe frame10 = Keyframe.ofFloat(1, 0);
                    PropertyValuesHolder frameHolder1 = PropertyValuesHolder.ofKeyframe("rotation", frame0, frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9, frame10);
    
    
                    /**
                     * scaleX放大1.1倍
                     */
                    Keyframe scaleXframe0 = Keyframe.ofFloat(0f, 1);
                    Keyframe scaleXframe1 = Keyframe.ofFloat(0.1f, 1.1f);
                    Keyframe scaleXframe9 = Keyframe.ofFloat(0.9f, 1.1f);
                    Keyframe scaleXframe10 = Keyframe.ofFloat(1, 1);
                    PropertyValuesHolder frameHolder2 = PropertyValuesHolder.ofKeyframe("ScaleX", scaleXframe0, scaleXframe1, scaleXframe9, scaleXframe10);
    
    
                    /**
                     * scaleY放大1.1倍
                     */
                    Keyframe scaleYframe0 = Keyframe.ofFloat(0f, 1);
                    Keyframe scaleYframe1 = Keyframe.ofFloat(0.1f, 1.1f);
                    Keyframe scaleYframe9 = Keyframe.ofFloat(0.9f, 1.1f);
                    Keyframe scaleYframe10 = Keyframe.ofFloat(1, 1);
                    PropertyValuesHolder frameHolder3 = PropertyValuesHolder.ofKeyframe("ScaleY", scaleYframe0, scaleYframe1, scaleYframe9, scaleYframe10);
    
                    /**
                     * 构建动画
                     */
                    Animator animator = ObjectAnimator.ofPropertyValuesHolder(mImg, frameHolder1, frameHolder2, frameHolder3);
                    animator.setDuration(1000);
                    animator.start();
                }
            });
        }
    }

    效果:

  • 相关阅读:
    已解决: 已引发: "无法加载 DLL“opencv_core2410”: 找不到指定的模块。
    Xcode 设置图片全屏显示
    独创轻松实现拖拽,改变层布局
    WCF Odata 开放数据协议应用
    MVC中,加入的一个aspx页面用到AspNetPager控件处理办法
    关于 HRESULT:0x80070
    Springboot文件上传大小设置
    Jquery Validate 表单验证使用
    Quartz任务调度框架使用
    js中常见命令
  • 原文地址:https://www.cnblogs.com/loaderman/p/10207077.html
Copyright © 2011-2022 走看看