Three animated frame animations, motion tweens, and property animations based on Android.

Source: Internet
Author: User

Frame Animation drawable Animation

Declaring a frame animation through an XML file

① Create a drawable directory under the Res directory to put the image resources used in this directory and create an XML file

The root element animation-list can be set to a property oneshot if the animation is set to true only once execution stops at the last frame

Animation-list child element Item

<?XML version= "1.0" encoding= "Utf-8"?>2.<animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"3. Android:oneshot= "true" > //Kick People's animations 4.<Itemandroid:drawable= "@drawable/girl_1"android:duration= "$" />5.<Itemandroid:drawable= "@drawable/girl_2"android:duration= "$" />6.<Itemandroid:drawable= "@drawable/girl_3"android:duration= "$" />7.<Itemandroid:drawable= "@drawable/girl_4"android:duration= "The " />8.<Itemandroid:drawable= "@drawable/girl_5"android:duration= "The " />9.<Itemandroid:drawable= "@drawable/girl_6"android:duration= "The " />.<Itemandroid:drawable= "@drawable/girl_4"android:duration= "The " />One by one .<Itemandroid:drawable= "@drawable/girl_5"android:duration= "The " />.<Itemandroid:drawable= "@drawable/girl_6"android:duration= "The " />.<Itemandroid:drawable= "@drawable/girl_4"android:duration= "The " />.<Itemandroid:drawable= "@drawable/girl_5"android:duration= "The " />A .<Itemandroid:drawable= "@drawable/girl_6"android:duration= "The " />.<Itemandroid:drawable= "@drawable/girl_7"android:duration= "The " />.<Itemandroid:drawable= "@drawable/girl_8"android:duration= "The " />.<Itemandroid:drawable= "@drawable/girl_9"android:duration= "$" />.<Itemandroid:drawable= "@drawable/girl_10"android:duration= "$" />.<Itemandroid:drawable= "@drawable/girl_11"android:duration= "$" />.</animation-list>

The Drawable property in item corresponds to the picture resource used by the current frame duration specifies the length of time each frame plays

② is loaded in the layout file of the interface via the ImageView Background property drawableanimation

<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2. Xmlns:tools= "Http://schemas.android.com/tools"3. Android:layout_width= "Match_parent"4. Android:layout_height= "Match_parent"5. Android:paddingbottom= "@dimen/activity_vertical_margin"6. Android:paddingleft= "@dimen/activity_horizontal_margin"7. Android:paddingright= "@dimen/activity_horizontal_margin"8. Android:paddingtop= "@dimen/activity_vertical_margin"9. Tools:context=". Mainactivity " >10.11. <ImageViewAndroid:id.= "@+id/iv_animation"android:layout_width.= "Wrap_content"android:layout_height.= "Wrap_content"Android:background.= "@drawable/drawableanimation" />.</Relativelayout>

③ found in the Java code ImageView getbackground find the Drawableanimation resource and start the animation

public class Mainactivity extends Activity {2.   3.      @Override4.      protected void OnCreate (Bundle savedinstancestate) {5.          Super.oncreate (savedinstancestate); 6.          Setcontentview (R.layout.activity_main); 7.          ImageView iv_image = (ImageView) Findviewbyid (r.id.iv_animation); 8.          Find ImageView Background Resources This background is a frame animation strongly into the frame animation corresponding to the Animationdrawable object 9.         Animationdrawable anim =  (animationdrawable) iv_image.getbackground ();       Start the animation one by one.       Anim.start ();    

Three animated frame animations, motion tweens, and property animations based on Android.

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.