In making references we can introduce Android animations to make the user feel more interactive, let's take a look at an example of how to use the Android animation to achieve the window's jitter effect.
1. Introduce the animation file:
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" android:interpolator= "@anim/cycle" > <translate android:fromxdelta= "0" android: Toxdelta= " -10" android:fromydelta= "0" android:toydelta= " -10" android:duration= "/>" < Translate android:fromxdelta= "0" android:toxdelta= " android:fromydelta=" 0 " android: Toydelta= " -10" android:startoffset= "android:duration=" /> <translate android : Fromxdelta= "0" android:toxdelta= " -10" android:fromydelta= "0" android:toydelta= "ten" android:startoffset= "android:duration=" /> <translate android:fromxdelta= "0" android:toxdelta= "Ten" android:fromydelta= "0" android:toydelta= " android:startoffset=" " android:duration="/></set>
2. layout file:
<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 "Tools:context =". Mainactivity "android:background=" #FF6A6A "android:gravity=" center "> <relativelayout android:id=" @+ Id/rel "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:background=" @android: Color/white "> <textview android:id=" @+id/edit "android:layout_width=" 200DP " android:layout_height= "200DP" android:layout_alignparenttop= "true" Android:layout_centerho Rizontal= "true" android:layout_margintop= "66DP" android:background= "@drawable/abs"/> < Button android:id= "@+id/btn" android:layout_width= "Wrap_content" android:layout_height= "W Rap_content "Android:layout_below= "@+id/edit" android:layout_centerhorizontal= "true" android:layout_margintop= "66DP" and roid:text= "Click to shake Picture"/> </RelativeLayout></RelativeLayout>
3.java file, we introduce animations to make the Relativelayout layout wobble:
Package Com.example.windowjitter;import Android.app.activity;import Android.os.bundle;import android.view.Menu; Import Android.view.view;import Android.view.animation.animation;import android.view.animation.AnimationUtils; Import android.widget.button;import android.widget.relativelayout;/** * Window jitter * * @author Yayun * */public class Mainacti Vity extends Activity {private relativelayout rel;private Button btn; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); rel = ( Relativelayout) This.findviewbyid (r.id.rel); btn = (Button) This.findviewbyid (R.ID.BTN); Btn.setonclicklistener (new Button.onclicklistener () {@Overridepublic void OnClick (View v) {Animation anim = animationutils.loadanimation ( Mainactivity.this, R.anim.myanim); Rel.startanimation (Anim);}}); @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.activity_main, menu); return true;}}
Run the following example:
On the left column, Welcome to my blog!
SOURCE download
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Combat Simple tutorial-67th gun (Android Animation to achieve window jitter effect)