android view的抖動效果

如果想讓一個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);就可以抖起來了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章