[mobilesafe] 06_搜索系统某个功能的源码——输入框为空的抖动动画效果

Android 4.0

输入框为空的抖动动画效果-API Demos

用户在EditText中输入为空时,抖动 一下的动画
位置:
API Demos→Views→Animation→Shake

导入Android源码到Eclipse中:
要搜如何实现的?
1、先搜字符串strings.xml


<string name="animation_1_instructions">Please enter your password:</string>  
2、在CTRL+H搜索引用该字符串"animation_1_instructions"的布局文件
3、再CTRL+H,R.layout.animation_1,找到引用该布局文件的Acitvity

4、搜索结果

5、系统实现:
public class Animation1 extends Activity implements View.OnClickListener {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.animation_1);
        View loginButton = findViewById(R.id.login);
        loginButton.setOnClickListener(this);
    }
    public void onClick(View v) {
        Animation shake = AnimationUtils.loadAnimation(thisR.anim.shake);
        findViewById(R.id.pw).startAnimation(shake);
    }
}
6、引入相应的文件
a) 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" />
//android:interpolator是一个动画插入器,是一个数学函数,指定动画以什么方式进行展现。
b)cycle_7.xml
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />
//cycles="7" 系统定义的函数,循环播放7次