仿照天天动听的登录验证EditView输入框抖动效果

模仿天天动听的登录验证EditView输入框抖动效果

仿照天天动听的登录验证EditView输入框抖动效果

当点击登录时, 会验证是否输入用户名或者密码,如果没有输入则 抖动输入框 提醒用户!

     抖动的效果其实很简单 就是一个动画 改变X坐标, 并加入循环


  关键代码如下:

  首先动画代码:shake.xml:

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

<?xml version="1.0" encoding="utf-8"?>
    <cycleInterpolator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:cycles="6" />
cycles="6"指输入框来回抖动6次


.java:

et_username = (EditText) findViewById(R.id.et_username);
et_password = (EditText) findViewById(R.id.et_password);
Animation anim=AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake);
	
et_username.startAnimation(anim);//给输入编辑框开启动画		
et_password.startAnimation(anim);