JayceLi  

首先在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);

 

posted on 2012-05-16 14:32  JayceLi  阅读(2620)  评论(1编辑  收藏  举报