Android抖动的动画效果

首先在res/anim中定义一个动画的xml, shake.xml:

1 <translate xmlns:android="http://schemas.android.com/apk/res/android" 
2     android:fromXDelta="0" 
3     android:toXDelta="10" 
4     android:duration="300" 
5     android:interpolator="@anim/cycle" />

然后在res/anim中定义一个cycle.xml,来控制抖动次数的,这里用的5次:

1 <cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" 
2     android:cycles="5" />

然后在java代码中使用此动画:

1 Animation shake = AnimationUtils.loadAnimation(mContext, R.anim.shake);  
2 yourview.startAnimation(shake);
原文地址:https://www.cnblogs.com/jayceli/p/2503955.html