當(dāng)我們面臨一些登錄等操作時(shí)難免會(huì)遇到操作失敗的情況,此時(shí)我們可以采用一種比較活潑的方式與用戶交互:給Button或者View添加一個(gè)抖動(dòng)動(dòng)畫(huà)。代碼如下:
/**
* @param view 需要抖動(dòng)的view
* @param deltax x方向抖動(dòng)的幅度
* @param duration 持續(xù)的時(shí)間
* @param repeatCount 重復(fù)抖動(dòng)的次數(shù)
*/
public void setShakeAnim(View view,int deltax,long duration,int repeatCount ){
Animation animation2 = new TranslateAnimation(-10, 10, 0, 0);
animation2.setDuration(50);
animation2.setRepeatCount(3);
animation2.setRepeatMode(Animation.RESTART);
view.startAnimation(animation2);
};