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 a" ndroid:drawable= "@drawable/ben_window_0003" android:duration= "/> <item android:drawable=" @ drawable/ben_window_0004 "android:duration=" "/> <item android:drawable=" @drawable/ben_windo            w_0005 "android:duration="/> <item android:drawable= "@drawable/ben_window_0006" android:duration= "/> <item android:drawable=" @drawable/ben_window_0007 "android:duration=     "/>" <item android:drawable= "@drawable/ben_window_0008" android:duration= " <item android:drawable= "@drawable/ben_window_0009 "android:duration=" "/> <item android:drawable=" @drawable/ben_window            _0010 "android:duration="/> <item android:drawable= "@drawable/ben_window_0011" android:duration= "/> <item android:drawable=" @drawable/ben_window_0012 "android:duration="    "/> <item android:drawable=" @drawable/ben_window_0013 "android:duration="/> <item android:drawable= "@drawable/ben_window_0014" android:duration= "/> <item androi d:drawable= "@drawable/ben_window_0015" android:duration= "/> <item android:drawable=" @drawa ble/ben_window_0016 "android:duration=" "/> <item android:drawable=" @drawable/ben_window_001 7 "android:duration="/> <item android:drawable= "@drawable/ben_window_0018" Android       oid:duration= "60"  /> <item android:drawable= "@drawable/ben_window_0019" android:duration= "/> <ite" M android:drawable= "@drawable/ben_window_0020" android:duration= "/> <item android:drawable = "@drawable/ben_window_0021" android:duration= "/> <item android:drawable=" @drawable/ben_wi            ndow_0022 "android:duration="/> <item android:drawable= "@drawable/ben_window_0023" android:duration= "/> <item android:drawable=" @drawable/ben_window_0024 "Android:durati on= "/> <item android:drawable=" @drawable/ben_window_0025 "android:duration=" 60 "/&    Gt <item android:drawable= "@drawable/ben_window_0026" android:duration= "/> <item android:d rawable= "@drawable/ben_window_0027" android:duration= "/> <item android:drawable=" @drawable /ben_window_0028 "            android:duration= "/> </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:duration= "xmlns:android=" "                http://schemas.android.com/apk/res/android" >    <!--  transparency 0-1  0 Fully transparent  1 completely opaque--></alpha>


<?xml version= "1.0" encoding= "Utf-8"? ><rotate  android:fromdegrees= "0"         android:todegrees= "360"         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 Count    Infinite Infinite           Repeatmode    repeating 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 Master file

It's just a picture, plus a couple of 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);} Perform transparent animation public void alpha (View v) {//1. Load Animation resource Animation Anim = Animationutils.loadanimation (Mainactivity.this, R.anim.alpha);//2. Perform animation image.startanimation (ANIM);}       Perform 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);}}


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.