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
<?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的更多相关文章
- 【Android UI】Android开发之View的几种布局方式及实践
引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...
- Android开发之View重写相关API-onLayout,onMeasure,MeasureSpec
1.onLayout android.view.ViewGroup protected void onLayout(boolean changed, int l, int t, int r, int ...
- Android 动画之View动画效果和Activity切换动画效果
View动画效果: 1.>>Tween动画通过对View的内容进行一系列的图形变换(平移.缩放.旋转.透明度变换)实现动画效果,补间动画需要使用<set>节点作为根节点,子节点 ...
- Android开发之PopupWindow
/* * Android开发之PopupWindow * * Created on: 2011-8-8 * Author: blueeagle * Email: liujiaxiang@g ...
- android开发之Animations的使用(二)
android开发之Animations的使用(二) 本博文主要讲述的是android开发中的animation动画效果的使用,和上一篇博文不同的是,此次四种动画效果,主要使用的是xml文件实现的,提 ...
- android开发之Animation(五)
android开发之Animation的使用(五) 本博文主要讲述的是Animation中的AnimationLisenter的用法,以及此类的一些生命周期函数的调用,代码实比例如以下: MainAc ...
- Android开发之InstanceState详解
Android开发之InstanceState详解 本文介绍Android中关于Activity的两个神秘方法:onSaveInstanceState() 和 onRestoreInstanceS ...
- Android开发之ViewPager+ActionBar+Fragment实现响应式可滑动Tab
今天我们要实现的这个效果呢,在Android的应用中十分地常见,我们可以看到下面两张图,无论是系统内置的联系人应用,还是AnyView的阅读器应用,我们总能找到这样的影子,当我们滑动屏幕时,Tab可 ...
- android中设置Animation 动画效果
在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...
随机推荐
- CSS3.0动画之hover---Y轴----3D旋转
div#div2{display: table; width: 100%; height: 100%; text-decoration: none; outline: none; -webkit-tr ...
- 在后台对GameObject进行"创建"||"删除"动作
在后台对GameObject进行"创建"||"删除"动作 建立 public GameObject Pre;//在编辑器中用来绑定的Prefabs public ...
- http://phantomjs.org/page-automation.html
http://phantomjs.org/page-automation.html install brew curl -LsSf http://github.com/mxcl/homebrew/ta ...
- Java实现MySQL在线管理
问题: 1.如何实现在线创建MySQL数据库.表: 2.如何实现在线执行sql语句? 思路: 1.可以通过java.sql.Statement类的executeUpdate(String sql)方法 ...
- Oracle的rownum原理
Oracle中,按特定条件查询前N条记录,用个rownum就搞定了: SQL> select * from dept where rownum<3; 而对rownum用"> ...
- ENVI栅格文件增强后将LUT保存完输出img图像进行分类
ENVI栅格文件储存 图像原始的DN(Digital Number)值记录图像的光谱信息,不能轻易更改。在窗口中显示的一般是经过拉伸等增强处理的LUT上的灰度值,在保存文件时,就有不同的方式。 1. ...
- bootstrap 框架选型过程
1.看有没有帮助文档,帮助文档的完整程度. 2.是否是我们业务需要的,花哨的功能真的有用吗? 对于偏pc端使用的系统 toggles意义不大 bootstrap和extjs的区别是什么呢? easyU ...
- 移动APP学习笔记一
登录 ●登录用户名和密码错误时,界面有提示信息 ●用户主动退出登录后,下次启动APP时,应该进入登录界面 ●对于支持自动登录的APP,数据交换时 ,是否能自动登录成功且数据库操作无误 ●密码更改后, ...
- main函数(本文较老,仅作参考)
Xcode4.2之前的main函数如下: int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePoo ...
- poj 1236 Network of Schools(又是强连通分量+缩点)
http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Su ...