zoukankan      html  css  js  c++  java
  • Android开发之View动画效果插补器Interpolator

    插补器Interpolator

    官网描述:An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated, etc.

    Google翻译:Interpolator可以限定一个动画的变化率。 这样的话,可以对基本的动画效果(比如透明、缩放、位移、旋转)进行加速、减速、重复等

    参考APIDemo中Views>Animation>Interpolator

    下图是Interpolator的一些属性,可以对动画中Interpolator属性设置为以下资源内容,实现动画效果。

    实例:(对输入框实现摇晃效果)

    anim/cycle_7.xml

    1 <?xml version="1.0" encoding="utf-8"?>
    2 <cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
    3     android:cycles="7" />     //周期运动7次

    anim/shake.xml

    1 <?xml version="1.0" encoding="utf-8"?>
    2 
    3 <translate xmlns:android="http://schemas.android.com/apk/res/android"
    4     android:duration="1000"
    5     android:fromXDelta="0"
    6     android:interpolator="@anim/cycle_7"      //设置该动画从x到y移动10,来回7次。
    7     android:toXDelta="10" />

    R.id.pw为一个EditText。

    1 public void onClick(View v) {
    2         Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
    3         findViewById(R.id.pw).startAnimation(shake);         //给输入框pw设置动画属性
    4     }

    --------------------------------------------------------------------------------------------------------------------------------------------------

    插补器Interpolator

    代码实现(对动画对象设置一个插补器,并实现插补器中的getInterpolation方法。该方法主要是数学知识,描述物体运动轨迹的计算公式,比如正弦,余弦,或者y=x等)

     1 Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
     2 shake.setInterpolator(new Interpolator() {
     3 
     4     @Override
     5     public float getInterpolation(float x) {
     6     //实现插补器的逻辑   
    int y = x;
    7 return y; 8 } 9 }); 10 findViewById(R.id.pw).startAnimation(shake);
  • 相关阅读:
    DOPE:基于蒸馏网络的全身三维姿态估计
    3D人体姿态重构
    Nginx+gunicorn+flask+docker算法部署
    MediaPipe中Box Tracking技术原理
    C++线程池
    MediaPipe加速流程和原理
    记一次illegal instruction问题定位
    如何阅读大工程代码(clickhouse版)
    zookeeper client原理总结
    go package依赖图自动生成
  • 原文地址:https://www.cnblogs.com/liyiran/p/5143614.html
Copyright © 2011-2022 走看看