View

Android实现EditText的抖动效果

2018-04-04  本文已影响0人  majorty

很多时候,我们都要提醒用户输入框的内容不能为空。通常我们都会弹出一个Toast来提醒用户,有一个更加人性化的提醒方式,就是让输入框抖一下。效果图如下:


shake.gif

代码调用:

Animation shake = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.shake);
mEtPhone.startAnimation(shake);

shake.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromXDelta="0" 
    android:toXDelta="10" 
    android:duration="1000" 
    android:interpolator="@anim/cycle_7" />

cycle_7.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />
上一篇 下一篇

猜你喜欢

热点阅读