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);
  • 相关阅读:
    我的访问量咋才3万了
    Khronos发布WebGL标准规范 1.0
    X3Dom V1.2发布
    解决Linux(Fedora Ubuntu)笔记本的待机休眠
    多用户虚拟Web3D环境Deep MatrixIP9 1.04发布
    网络科技公司Web开发团队管理的小结
    XamlReader 动态加载XAML
    Excel Data Reader开源的.NET excel读取库
    .net Sql server 事务的两种用法
    通过使用客户端证书调用 Web 服务进行身份验证{转}
  • 原文地址:https://www.cnblogs.com/liyiran/p/5143614.html
Copyright © 2011-2022 走看看