Java代碼:啟動動畫
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
findViewById(R.id.pw).startAnimation(shake);
anim/shake.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="0"
android:interpolator="@anim/cycle_7"
android:toXDelta="10" />
duration為抖動時間,fromXDelta,toXDelta抖動幅度
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="10" />
EditText
<EditText android:id="@+id/pw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>