一个喜欢安静的博主

输入框抖动和震动特效

  • 首先,在代码中作如下判断

    1. if(TextUtils.isEmpty(address)){

    2. Animation animation =AnimationUtils.loadAnimation(NumberAdresss.this, R.anim.shake);

    3. et_number.startAnimation(animation);

    4. if(vibrator.hasVibrator()){//如果支持震动

    5. vibrator.vibrate(newlong[]{100,200,100,200,100,200},5);

    6. }

    7. }

    其中 Vibrator使用调用服务的方式创建

    Vibrator vibrator =(Vibrator) getSystemService(VIBRATOR_SERVICE);

  • 我们发现里面有个动画文件,其实是两个,把这两个复制到anim就可以了

  • shake.xml

    1. <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 ,代码如下

    1. <cycleInterpolatorxmlns:android="https://schemas.android.com/apk/res/android"android:cycles="7"/>


评论

© x-surfer | Powered by LOFTER