See Apidemos, find View/animation/shake find the corresponding animation code, direct copy over
When importing a project, the R file does not exist, in many cases the XML file is wrong
Animation shake = Animationutils.loadanimation (this, r.anim.shake);
Et_phone.startanimation (shake);
Animated XML File Shake.xml
Android:interpolator= "@anim/cycle_7"
Interpolator is an INSERT, you can define the speed of the animation, etc.
Invokes the Setinterpolator () method of the animation object, setting the INSERT, Parameter: Interpolator object
Implement the Interpolator interface anonymously, rewrite the Getinterpolation () method, set the custom animation rate, and pass in a flaot x
The vibration effect of the input frame
Gets the vibrator object, calls the Getsystemservice () method, Parameters: Vibrator_service
Call the Vibrator object's vibrate () method, parameters: milliseconds
Need to add permissions Android.permission.VIBRATE
This can do some vibrator ~
/**
* Query Attribution/
public
void Querynumber (View v) {
phone = Et_phone.gettext (). toString (). Trim ();
if (Textutils.isempty (phone)) {
//dither animation
Animation shake = Animationutils.loadanimation (this, r.anim.shake);
Et_phone.startanimation (shake);
Mobile phone Vibration
vibrator.vibrate ();
Toast.maketext (This, "Please enter your mobile number", 0). Show ();
return;
}
String result = numberqueryaddressutil.queryaddress (phone);
Tv_address.settext (result);
}
Shake.xml
<translate xmlns:android= "http://schemas.android.com/apk/res/android"
android:duration= "1000"
Android:fromxdelta= "0"
android:interpolator= "@anim/cycle_7"
Cycle_7.xml
<cycleinterpolator xmlns:android= "Http://schemas.android.com/apk/res/android" android:cycles= "7"/>
The above is a small series to introduce the Android phone defender's input frame jitter and mobile phone vibration related content, I hope to help you!