插补器Interpolator
参考APIDemo中Views>Animation>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" />
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" 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); 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 //实现插补器的逻辑 7 return y; 8 } 9 }); 10 findViewById(R.id.pw).startAnimation(shake);
Android开发之View动画效果插补器Interpolator
原文:http://www.cnblogs.com/liyiran/p/5143614.html