首先,在代码中作如下判断
if(TextUtils.isEmpty(address)){
Animation animation =AnimationUtils.loadAnimation(NumberAdresss.this, R.anim.shake);
et_number.startAnimation(animation);
if(vibrator.hasVibrator()){//如果支持震动
vibrator.vibrate(newlong[]{100,200,100,200,100,200},5);
}
}
其中 Vibrator使用调用服务的方式创建
Vibrator vibrator =(Vibrator) getSystemService(VIBRATOR_SERVICE);
我们发现里面有个动画文件,其实是两个,把这两个复制到anim就可以了
shake.xml
<translatexmlns:android="https://schemas.android.com/apk/res/android"android:fromXDelta="0"android:toXDelta="10"android:duration="1000"android:interpolator="@anim/cycle_7"/>
这里面又引用了另一个cycle_7.xml ,代码如下
<cycleInterpolatorxmlns:android="https://schemas.android.com/apk/res/android"android:cycles="7"/>