[Android] Mobile defender input box jitter and phone shake

Source: Internet
Author: User

Check Apidemos, find view/animation/shake to find the corresponding animation code, directly copied 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 a plug-in that can define the speed of the animation, etc.

Call the Setinterpolator () method of the Animation Object , set the caret, parameter:interpolator Object

Implement the interpolator interface anonymously, override the getinterpolation () method, set the custom animation rate, pass in a flaot x

Vibration Effect of input box

Get the vibrator object, call the getsystemservice () method, Parameter:vibrator_service

Call the vibrate () method of the Vibrator Object , parameter: milliseconds

Need to add permissions Android.permission.VIBRATE

This can do some vibrators ~

    /** * Enquiry of place of Attribution*/ PublicvoidQuerynumber (View v) {phone=Et_phone.gettext (). toString (). Trim (); if(Textutils.isempty (phone)) {//jitter AnimationsAnimation shake = Animationutils.loadanimation ( This, R.anim.shake);            Et_phone.startanimation (shake); //Mobile phone VibrationVibrator.vibrate (2000); Toast.maketext ( This, "Please enter your mobile number", 0). Show (); return; The String result=numberqueryaddressutil.queryaddress (phone);    Tv_address.settext (result); }

Shake.xml

<xmlns:android= "http://schemas.android.com/apk/res/android"    Android :d uration= "    android:fromxdelta"= "0"    Android:interpolator  = "@anim/cycle_7"    android:toxdelta= "Ten"/>

Cycle_7.xml

<xmlns:android= "http://schemas.android.com/apk/res/android"  android: Cycles= "7"/>

[Android] Mobile defender input box jitter and phone shake

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.