This article describes the implementation methods of Tween animation and Frame animation in Android programming. Share it for your reference, as follows:
Animation has two main animation modes: Tween animation and Frame animation
Tween animation consists of four types
Create new anim in the res directory
<?xml version="1.0" encoding="utf-8"?> <set xmlns:andro> <!-- transparent --> <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="3000" /> <!-- Rotate --> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="3000" /> <!-- Zoom --> <scale android:fromXScale="1" android:fromYScale="1" android:toXScale="3" android:toYScale="3" android:pivotX="0" android:pivotY="0" android:duration="3000" /> <!-- move --> <translate android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="50%p" android:toYDelta="50%p" android:duration="3000" /> </set>
Each of the above animation effects can be placed in different xml files to view the effects.
Below is the call animation in Activity
public void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(); imageView = (ImageView) findViewById(); } public void onClick(View view) { Animation animation = null; switch (()) { case : animation = (this, ); break; case : animation = (this, ); break; case : animation = (this, ); break; case : //animation = (this, ); //Let a way to create RotateAnimation in JavaCode animation = new RotateAnimation(0, 180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); (3000); break; case : animation = (this, ); break; } //Start the animation (animation); }
Tween animation consists of four types
Frame animation consists of multiple pictures and multiple pictures are looped.
Example:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:andro android:oneshot="false"> <item android:drawable="@drawable/p1" android:duration="200" /> <item android:drawable="@drawable/p2" android:duration="200" /> <item android:drawable="@drawable/p3" android:duration="200" /> <item android:drawable="@drawable/p4" android:duration="200" /> <item android:drawable="@drawable/p5" android:duration="200" /> <item android:drawable="@drawable/p6" android:duration="200" /> <item android:drawable="@drawable/p7" android:duration="800" /> <item android:drawable="@drawable/p8" android:duration="200" /> <item android:drawable="@drawable/p9" android:duration="200" /> <item android:drawable="@drawable/p10" android:duration="200" /> <item android:drawable="@drawable/p11" android:duration="200" /> </animation-list>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro 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 animation image on the ImageView AnimationDrawable drawable = (AnimationDrawable) (); // The animation begins (); }
I hope this article will be helpful to everyone's Android programming design.