Analysis of Jitter Input Box and Mobile Phone Vibration of Android Mobile Phone Guardian
- 2021-07-09 09:08:09
- OfStack
Look at apiDemos, find View/Animation/shake, find the corresponding animation code, and copy it directly
When importing a project, the report 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 inserter, which can define the speed of animation and so on
Call the setInterpolator () method of the Animation object to set the inserter, parameter: Interpolator object
Anonymously implement Interpolator interface, override getInterpolation () method, set custom animation rate, pass in 1 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, argument: milliseconds
Need to add permissions android. permission. VIBRATE
This can be used as a vibrator ~
/**
* Inquiry of attribution
*/
public void queryNumber(View v) {
phone = et_phone.getText().toString().trim();
if (TextUtils.isEmpty(phone)) {
// Jitter animation
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
et_phone.startAnimation(shake);
// Mobile phone vibration
vibrator.vibrate(2000);
Toast.makeText(this, " Please enter your mobile phone 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"
android:toXDelta="10" />
cycle_7.xml
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />
The above is the site to introduce the Android mobile phone guard of the input box jitter and mobile phone vibration related content, I hope to help you!