Tween animation and frame animation example analysis in Android programming _android

Source: Internet
Author: User

This article describes the tween animation and frame animation implementation method in Android programming. Share to everyone for your reference, specific as follows:

Animation mainly has two kinds of animation modes: Tween animation and frame animation

Tween animations are made up of four types

Alpha
Gradient Transparency Animation effect
Scale
Gradient Size Telescopic animation effect
Translate
Moving animation effect in the position of picture transformation
Rotate
Picture Transfer rotation animation effect

New Anim Create Tween.xml in res directory

<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
 <!--transparent-->
 <alpha
 android:fromalpha=" 1 "
 android:toalpha=" 0 "
 android: duration= "3000"
 />
 <!--rotate-->
 <rotate
 "0"
 android: todegrees= "360"
 android:pivotx= "50%" android:pivoty= "50%"
 android:duration= "3000
 "/>
 <!--scaling-->
 <scale
 android:fromxscale= "1"
 android:fromyscale= "1"
 android: Toxscale= "3"
 android:toyscale= "3"
 android:pivotx= "0"
 android:pivoty= "0"
 android:duration= " 3000 "
 />
 <!--mobile-->
 <translate
 android:fromxdelta=" 0 "
 android:fromydelta=" 0 "
 android:toxdelta=" 50%p "Android:toydelta=" 50%p "android:duration=" 3000 "/>
< /set>

Each of these animation effects can be placed in a different XML file for easy viewing of the effect

Below is the call animation in the activity

 public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
 Setcontentview (R.layout.main);
ImageView = (ImageView) Findviewbyid (r.id.img);
 public void OnClick (view view) {Animation Animation = null;
  Switch (View.getid ()) {Case r.id.alpha:animation = animationutils.loadanimation (this, r.anim.alpha);
 Break
  Case r.id.scale:animation = Animationutils.loadanimation (this, r.anim.scale);
 Break
  Case r.id.translate:animation = Animationutils.loadanimation (this, r.anim.translate);
 Break
  Case r.id.rotate://animation = Animationutils.loadanimation (this, r.anim.rotate); Make a way to create rotateanimation animation = new Rotateanimation (0, 180, rotateanimation.relative_to_self, 0.5f, Rota Javacode)
  Teanimation.relative_to_self, 0.5f);
  Animation.setduration (3000);
 Break
  Case r.id.all:animation = Animationutils.loadanimation (this, r.anim.tween);
 Break
}//Start animation imageview.startanimation (animation); }

Tween animations are made up of four types

Frame animation is composed of more than one picture, multiple picture loops.

Example:

Frame.xml

 <?xml version= "1.0" encoding= "Utf-8"?> "<animation-list xmlns:android=" http:// Schemas.android.com/apk/res/android "android:oneshot= false" > <item android:drawable= "@drawable/p1" Android: duration= "/> <item android:drawable=" @drawable/p2 "android:duration=" "/> <item android:drawable=
 "@drawable/p3" android:duration= "/> <item android:drawable=" @drawable/p4 "android:duration="/> <item android:drawable= "@drawable/p5" android:duration= "/> <item android:drawable=" @drawable/p6 " Android:duration= "/>" <item android:drawable= "@drawable/p7" android:duration= "" "/> <item android: drawable= "@drawable/p8" android:duration= "/> <item android:drawable=" @drawable/p9 "android:duration=" 200 "/> <item android:drawable=" @drawable/p10 "android:duration="/> <item "@drawable" P11 "android:duration="/> </animation-list> 

Main.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
 android:orientation=" vertical "
 android:layout_width=" fill_parent "
 android:layout_" height= "Fill_parent"
 >
 <imageview
 android:layout_width= "wrap_content"
 android:layout_ height= "Wrap_content"
 android:src= "@anim/frame"
 android:onclick= "Go"
 />
</ Linearlayout>

Activity:

public void Go (view view) {
 //Get ImageView
 imageview ImageView = (imageview) View;
 Get the animated picture above ImageView
 animationdrawable drawable = (animationdrawable) imageview.getdrawable ();
 Animation start
 Drawable.start ();
}

I hope this article will help you with the Android program.

Related Article

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.