Android------2 animation effect

Source: Internet
Author: User

1, first look at Frameanimation, this animation is used to achieve dynamic animation is to take a frame picture of the iteration up

XML that is placed in drowable:

<?xml version= "1.0" encoding= "Utf-8"?

><animation-list xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:drawable= " @drawable/ben_window_0001 "android:duration=" "/> <item android:drawable=" @drawable /ben_window_0002 "android:duration="/> <item android:drawable= "@drawable/ben_window_0003" android:duration= "/> <item android:drawable=" @drawable/ben_window_0004 "Android :d uration= "/> <item android:drawable=" @drawable/ben_window_0005 "android:duration=" 60 " /> <item android:drawable= "@drawable/ben_window_0006" android:duration= [/>] < Item android:drawable= "@drawable/ben_window_0007" android:duration= "/> <item Android:drawa ble= "@drawable/ben_window_0008" android:duration= "/> <item android:drawable=" @drawable/ben _window_0009 "Androidoid:duration= "/> <item android:drawable=" @drawable/ben_window_0010 "android:duration=" 60 " /> <item android:drawable= "@drawable/ben_window_0011" android:duration= "the/>" Lt;item android:drawable= "@drawable/ben_window_0012" android:duration= "/> <item android:dr awable= "@drawable/ben_window_0013" android:duration= "/> <item android:drawable=" @drawable/ ben_window_0014 "android:duration="/> <item android:drawable= "@drawable/ben_window_0015" android:duration= "/> <item android:drawable=" @drawable/ben_window_0016 "Android: duration= "/> <item android:drawable=" @drawable/ben_window_0017 "android:duration=" 60 " /> <item android:drawable= "@drawable/ben_window_0018" android:duration= "/> <i" TEM android:drawable= "@drawable/ben_window_0019 "android:duration=" "/> <item android:drawable=" @drawable/ben_window _0020 "android:duration="/> <item android:drawable= "@drawable/ben_window_0021" android:duration= "/> <item android:drawable=" @drawable/ben_window_0022 "android:duration=" "/> <item android:drawable=" @drawable/ben_window_0023 "android:duration="/> <item android:drawable= "@drawable/ben_window_0024" android:duration= "/> <item androi d:drawable= "@drawable/ben_window_0025" android:duration= "/> <item android:drawable=" @drawa ble/ben_window_0026 "android:duration=" "/> <item android:drawable=" @drawable/ben_window_002 7 "android:duration="/> <item android:drawable= "@drawable/ben_window_0028" Android oid:duration= "60" /> </animation-list>


In activity:

Package Com.example.frameanimation;import Android.app.activity;import android.graphics.drawable.AnimationDrawable ; Import Android.os.bundle;import Android.view.view;import android.widget.button;public class MainActivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);} public void Startanimation (View v) {button btn= (button) v;//get animated object animationdrawable anim= (animationdrawable) Btn.getbackground ();//Start animation Anim.start ();}}

So I click on a tomcat and it will loop.



And then the motion tweens.



Look at these XML files first

<?

XML version= "1.0" encoding= "Utf-8"? ><alpha android:fromalpha= "0.1" android:toalpha= "1" Android :d uration= "xmlns:android=" http://schemas.android.com/apk/res/android > <!-- transparency 0-1 0 Totally transparent 1 totally opaque--></alpha>



<?

XML version= "1.0" encoding= "Utf-8"? ><rotate android:fromdegrees= "0" android:todegrees= " the" android:duration= " android:pivotx=" 50% " android:pivoty=" 50% "android:interpolator=" @android : Anim/accelerate_interpolator " android:repeatcount=" Infinite " android:repeatmode=" reverse " Xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--repeatcount repeat times Infinite Infinite repeatmode recurrent mode interpolator accelerator --></rotate>



<?

XML version= "1.0" encoding= "Utf-8"? ><scale android:fromxscale= "0.5" android:fromyscale= "0.5 " Android:toxscale= "2" android:toyscale= "2" android:pivotx= "50%" android:pivoty= "50%" android: duration= "android:repeatmode=" reverse " android:repeatcount=" Infinite " xmlns:android="/http Schemas.android.com/apk/res/android "> </scale><!-- fromxscale 1 Status--



<?xml version= "1.0" encoding= "Utf-8"?

><translate xmlns:android= "http://schemas.android.com/apk/res/android" android:fromxdelta= "0" Android:fromydelta= "0" android:toxdelta= "0" android:toydelta= "80%p" android:duration= " Android:repeatmode= "Reverse" android:repeatcount= "Infinite" > </translate>



XML in the main file

It's just a picture plus a couple buttons.

<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:paddi ngbottom= "@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 "> <imageview android:layout_width=" wrap_content "android:layout_height=" Wrap_content "      Android:layout_alignparenttop= "true" android:layout_centerhorizontal= "true" android:layout_margintop= "84DP"      android:src= "@drawable/heart" android:id= "@+id/myimg"/> <button android:id= "@+id/button3" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_alignbaseline= "@+id/bu Tton2 "android:layout_alignbottom=" @+id/button2"Android:layout_alignright=" @+id/myimg "android:text=" Zoom "android:onclick=" scale "/> <button Android:id= "@+id/button1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" and Roid:layout_alignparentleft= "true" android:layout_below= "@+id/myimg" android:layout_marginleft= "32DP" Andro id:onclick= "Alpha" android:text= "alpha"/> <button android:id= "@+id/button2" Android:layout_width= "W Rap_content "android:layout_height=" wrap_content "android:layout_alignbaseline=" @+id/button1 "android:layou T_alignbottom= "@+id/button1" android:layout_marginright= "35DP" android:layout_toleftof= "@+id/button3" Andro id:onclick= "Rotate" android:text= "rotate"/> <button android:id= "@+id/button4" android:layout_width= "Wra P_content "android:layout_height=" wrap_content "android:layout_alignleft=" @+id/button1 "Android:layout_belo W= "@+id/button1" android:text= "Displacement animation" android:onclick= "translate"/></relativelayout> 


These animations are then called in the activity

Package Com.example.tweenanimation;import Android.app.activity;import Android.os.bundle;import Android.view.View; Import Android.view.animation.animation;import Android.view.animation.animationutils;import Android.widget.imageview;public class Mainactivity extends Activity {private ImageView image; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Image = (ImageView) Findviewbyid (r.id.myimg);} Run transparent animation public void alpha (View v) {//1. Load Animation resource Animation Anim = Animationutils.loadanimation (Mainactivity.this, R.anim.alpha);//2. Run animation image.startanimation (ANIM);}       Run rotation animation public void rotate (View v) {Animation anim = animationutils.loadanimation (mainactivity.this,r.anim.rotate); Image.startanimation (ANIM);}       Scale animation public void scale (View v) {Animation anim = animationutils.loadanimation (Mainactivity.this,r.anim.scale); Image.startanimation (ANIM);} public void translate (View v) {Animation anim = AnimatioNutils.loadanimation (mainactivity.this,r.anim.translate); Image.startanimation (Anim);}}


Android------2 animation effect

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.