Directly on the demo, the usage is in the notes of the program, first on five slag,
Layout code:
<linearlayout 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:orien tation= "vertical" tools:context= "com.example.animation.MainActivity" > <linearlayout android:layout_wid Th= "Fill_parent" android:layout_height= "wrap_content" android:orientation= "Horizontal" > <Butto n android:id= "@+id/alpha" android:layout_width= "wrap_content" android:layout_height= "wrap _content "android:text=" gradually disappears "/> <button android:id=" @+id/rotate "Android:la Yout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Rotation"/> < ; Button android:id= "@+id/translationx" android:layout_width= "Wrap_content" Android:layout_ height= "Wrap_content" android:text="Move Around"/> <button android:id= "@+id/translationy" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "Move Up and Down"/> </LinearLayout> <button Android:id= "@+id/scalex" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "stretched around"/> <button android:id= "@+id/scaley" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "Up and Down"/> <textview android:id= "@+id/textview "Android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:layout_gravity=" ce Nter_horizontal "android:text=" animation example "Android:textsize=" 30sp "android:textcolor=" #00EE00 "/></li Nearlayout>
Main activity
Package Com.example.animation;import Android.animation.objectanimator;import Android.animation.ValueAnimator; Import Android.os.bundle;import Android.support.v7.app.actionbaractivity;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;public Class Mainactivity extends Actionbaractivity {private TextView TextView;p rivate button scaleX;p rivate button ScaleY;p rivate B Utton Alpha;p rivate button rotate;p rivate button translationx;p rivate button translationy;p rivate valueanimator va; @O verrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main) This.textview = (TextView) Findviewbyid (r.id.textview); This.alpha = (Button) Findviewbyid ( R.id.alpha) this.rotate = (Button) Findviewbyid (r.id.rotate); This.translationx = (Button) Findviewbyid ( R.id.translationx); this.translationy = (Button) Findviewbyid (r.id.translationy); This.scalex = (Button) findViewbyid (R.id.scalex); This.scaley = (Button) Findviewbyid (R.id.scaley); This.scaleX.setOnClickListener (new Onclicklistener () {@Overridepublic void OnClick (View v) {ScaleX ();}}); This.scaleY.setOnClickListener (New Onclicklistener () {@Overridepublic void OnClick (View v) {ScaleY ();}}); This.translationY.setOnClickListener (New Onclicklistener () {@Overridepublic void OnClick (View v) {translation (2);}}); This.translationX.setOnClickListener (New Onclicklistener () {@Overridepublic void OnClick (View v) {translation (1);}}); This.alpha.setOnClickListener (New Onclicklistener () {@Overridepublic void OnClick (View v) {alpha ();}}); This.rotate.setOnClickListener (New Onclicklistener () {@Overridepublic void OnClick (View v) {rotate ();}});} /* * Rotate animation */private void rotate () {This.va = Objectanimator.offloat (TextView, "rotation", 0f,360f); Rotate from 0 degrees to 360 degrees this.va.setDuration (5000); Set the rotation time from 0 degrees to 360 degrees//this.va.setrepeatcount (5); Repeat 5 times//this.va.setrepeatmode (Valueanimator.reverse); Play directly flip play//this.va.setrePeatmode (Valueanimator.restart); Play directly from the beginning This.va.start ();} /* * Move left and right translationy *flag==1 zuoyou *flag==2 shangxia */private void translation (int flag) {if (flag = = 1) This.va = Objectanimator.offloat (TextView, "Translationx", 0f,50f,5f); Left and Rightelse This.va = Objectanimator.offloat (TextView, "Translationy", 0f,50f,5f); Left and Rightthis.va.setDuration (1500); Set the rotation time from 0 degrees to 360 degrees This.va.setRepeatCount (5); Repeat 5 times//this.va.setrepeatmode (Valueanimator.reverse); Play the//this.va.setrepeatmode (Valueanimator.restart) directly and flip the playback. Play directly from the beginning This.va.start ();} /* * Move up or down move */private void Translationy () {This.va = Objectanimator.offloat (TextView, "Translationy", 0f,50f,5f); Left and Rightthis.va.setDuration (1500); Set the rotation time from 0 degrees to 360 degrees This.va.setRepeatCount (5); Repeat 5 times//this.va.setrepeatmode (Valueanimator.reverse); Play the//this.va.setrepeatmode (Valueanimator.restart) directly and flip the playback. Play directly from the beginning This.va.start ();} /* Change transparency (fade away) */private void Alpha () {This.va = ObjectanimaTor.offloat (This.textview, "alpha", 1f,0f,1f); Transparency changes from 1 to 0 and then to 1, and so on. This.va.setDuration (5000); Set the change interval//this.va.setrepeatcount (5); Repeat 5 times//this.va.setrepeatmode (Valueanimator.reverse); Play the//this.va.setrepeatmode (Valueanimator.restart) directly and flip the playback. Play directly from the beginning This.va.start ();} /* * Stretch */private void ScaleX () {This.va = Objectanimator.offloat (This.textview, "ScaleX", 1f,5f,1f); This.va.setDuration (//this.va.setrepeatcount); (5); Repeat 5 times//this.va.setrepeatmode (Valueanimator.reverse); Play the//this.va.setrepeatmode (Valueanimator.restart) directly and flip the playback. Play directly from the beginning This.va.start ();} /* * up and down stretched */private void ScaleY () {This.va = Objectanimator.offloat (This.textview, "ScaleY", 1f,5f,1f); This.va.setDuration (//this.va.setrepeatcount); (5); Repeat 5 times//this.va.setrepeatmode (Valueanimator.reverse); Play the//this.va.setrepeatmode (Valueanimator.restart) directly and flip the playback. Play directly from the beginning This.va.start ();}}
Android Properties Animation Valueanimator and Objectanimator detailed