如果想让一个View控件抖动起来,代码非常简单,只要控件的位置平移一下就行了
左右抖动:
TranslateAnimation anim = new TranslateAnimation(imageView.getWidth(),
imageView.getWidth() + 10, imageView.getHeight(), imageView.getHeight());
anim.setInterpolator(new CycleInterpolator(6f)); //循环次数
//CycleInterpolator:动画从开始到结束,变化率是循环给定次数的正弦曲线。
anim.setDuration( 500 ); //播放时间
上下抖动:
TranslateAnimation anim = new TranslateAnimation(imageView.getWidth(),
imageView.getWidth(), imageView.getHeight(), imageView.getHeight()+10);
anim.setInterpolator(new CycleInterpolator(6f));
anim.setDuration( 500 );
然后imagview.startAnimation(anim);就可以抖起来了