插补器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

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

anim/shake.xml

 <?xml version="1.0" encoding="utf-8"?>

 <translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="0"
android:interpolator="@anim/cycle_7" //设置该动画从x到y移动10,来回7次。
android:toXDelta="10" />

R.id.pw为一个EditText。

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

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

插补器Interpolator

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

 Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
shake.setInterpolator(new Interpolator() { @Override
public float getInterpolation(float x) {
//实现插补器的逻辑
int y = x;
return y;
}
});
10 findViewById(R.id.pw).startAnimation(shake);

Android开发之View动画效果插补器Interpolator的更多相关文章

  1. 【Android UI】Android开发之View的几种布局方式及实践

    引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...

  2. Android开发之View重写相关API-onLayout,onMeasure,MeasureSpec

     1.onLayout android.view.ViewGroup protected void onLayout(boolean changed, int l, int t, int r, int ...

  3. Android 动画之View动画效果和Activity切换动画效果

    View动画效果: 1.>>Tween动画通过对View的内容进行一系列的图形变换(平移.缩放.旋转.透明度变换)实现动画效果,补间动画需要使用<set>节点作为根节点,子节点 ...

  4. Android开发之PopupWindow

      /* *  Android开发之PopupWindow * *  Created on: 2011-8-8 *  Author: blueeagle *  Email: liujiaxiang@g ...

  5. android开发之Animations的使用(二)

    android开发之Animations的使用(二) 本博文主要讲述的是android开发中的animation动画效果的使用,和上一篇博文不同的是,此次四种动画效果,主要使用的是xml文件实现的,提 ...

  6. android开发之Animation(五)

    android开发之Animation的使用(五) 本博文主要讲述的是Animation中的AnimationLisenter的用法,以及此类的一些生命周期函数的调用,代码实比例如以下: MainAc ...

  7. Android开发之InstanceState详解

    Android开发之InstanceState详解   本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceS ...

  8. Android开发之ViewPager+ActionBar+Fragment实现响应式可滑动Tab

     今天我们要实现的这个效果呢,在Android的应用中十分地常见,我们可以看到下面两张图,无论是系统内置的联系人应用,还是AnyView的阅读器应用,我们总能找到这样的影子,当我们滑动屏幕时,Tab可 ...

  9. android中设置Animation 动画效果

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

随机推荐

  1. hibernate导入大量数据时,为了避免内存中产生大量对象,在编码时注意什么,如何去除?

    Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); for ( i ...

  2. 调用 GetProcAddress 失败,在 ISAPI 筛选器 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" 上

    1.选择网站的ISAPI筛选器,设置ASP.NET的 aspnet_filter.dll右键恢复为父项 如果问题还未解决,执行第2步: 2.是否注册了asp.net,打开cmd运行:C:\Window ...

  3. Android开发技巧:像QQ一样输入表情图像

     EditText和TextView一样,也可以进行图文混排.所不同的是,TextView只用于显示图文混排效果,而EditText不仅可显示, 也可混合输入文字和图像,让我们先回顾一下图5.2所示的 ...

  4. YII千万级PV架构经验分享--俯瞰篇--架构即产品

    hello,大家好,我是方少,今天想问大家一个问题,如果我们自己就是产品,那么我们怎样才能说服别人,我们是最优秀的呢?高学历,不错,别人成功过了.会php,java,c#,python不行再学c++, ...

  5. Gazebo Ros入门

    教程代码 First step with gazebo and ros • setup a ROS workspace • create projects for your simulated rob ...

  6. Linux进程间通信IPC学习笔记之同步二(Posix 信号量)

    Linux进程间通信IPC学习笔记之同步二(Posix 信号量)

  7. 1010. Radix (25)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  8. Only the original thread that created a view hierarchy can touch its views

    在调试软件的时候出现如下的错误: 01-05 20:53:36.492: E/ZZShip(2043): android.view.ViewRootImpl$CalledFromWrongThread ...

  9. sql之独立子查询和相关子查询总结

    1.独立子查询:顾名思义:就是子查询和外层查询不存在任何联系,是独立于外层查询的: 下面就看一个例子: 有一张订单表 Sales.Order 和一张 客户表 Sales.Customer 下面的sql ...

  10. ios 保存本地数据的方法

    1. NSString *path = [[NSBundle mainBundle] pathForResource:@"文件名" ofType:@"plist" ...