This article introduces the Android mobile phone vibration, jitter effect, share for everyone's reference, the specific contents are as follows
(1) The layout file is as follows
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http:// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android: paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: Context= ". Mainactivity "> <edittext android:id=" @+id/et_text "android:layout_width=" Wrap_content "Android:layout_height" = "Wrap_content" android:layout_alignparentleft= "true" android:layout_alignparentright= "true" Android:layout_
Alignparenttop= "true" android:layout_margintop= "16DP" android:ems= "ten" > <requestfocus/> </EditText> <button android:id= "@+id/btn_submit" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" a ndroid:layout_alignleft= "@+id/et_text" android:layout_below= "@+id/et_text" Android:layout_margintop= "38DP" android:text= "Submit"/> </RelativeLayout>
(2) Mainactivity.java
Package com.example.test11;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.os.Vibrator;
Import Android.text.TextUtils;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import android.view.animation.Animation;
Import Android.view.animation.AnimationUtils;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.Toast;
public class Mainactivity extends activity {private EditText et_text;
Private Button Btn_submit;
/** * Mobile Phone vibrator * * Private vibrator vibrator;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Et_text = (edittext) This.findviewbyid (R.id.et_text);
Btn_submit = (Button) This.findviewbyid (r.id.btn_submit);
Vibration effect of the system service Vibrator = (vibrator) getsystemservice (Vibrator_service);
Btn_submit.setonclicklistener (New Onclicklistener () {String text = Et_text.gettext (). toString (). Trim (); public void OnclicK (View v) {if (Textutils.isempty (text)) {Toast.maketext (mainactivity.this, "content is empty", 0). Show ();
Animation shake = Animationutils.loadanimation (Mainactivity.this, R.anim.shake);
Et_text.startanimation (shake); * * Vibration Mode///Vibrator.vibrate (2000)//Oscillation two seconds//below is to make the vibration of the regular vibration-1: Said not repeat 0: circular vibration long[] pattern = {200,
2000, 2000, 200, 200, 200};
Vibrator.vibrate (Pattern,-1);
}
}
});
}
}
(3) The following two animated files are used:
Cycle_7.xml
<?xml version= "1.0" encoding= "Utf-8"?> <cycleinterpolator xmlns:android=
"http://schemas.android.com/" Apk/res/android "
android:cycles=" 7 "/>
Shake.xml
<?xml version= "1.0" encoding= "Utf-8"?> <translate xmlns:android=
"http://schemas.android.com/apk/res/" Android "
android:duration=" 1000 "
android:fromxdelta=" 0 "
android:interpolator=" @anim/cycle_7 "
Android:toxdelta= "Ten"/>
(4) The permissions to be used:
<uses-permission android:name= "Android.permission.VIBRATE"/>
I hope this article will help you learn about Android software programming.