Simple use of frame animations in Android

Source: Internet
Author: User

There are several main types of animations in Android, frame animations (frames), motion tweens (tween), property animations

The main use of our project is frame animation and motion tweens


Frame animation requires us to prepare a set of static pictures, which are derived from the decomposition of the animation, the static picture is linked to play to form an animated effect

We create a new drawable directory under the Res directory to hold animation resources and XML files

The picture is as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/30/E7/wKiom1Ophl6Rj-aUAAGKnSDnP9M410.jpg "title=" 2.png " alt= "Wkiom1ophl6rj-auaagknsdnp9m410.jpg"/>


Girl.xml Note android:oneshot= "False|true" This property controls whether the animation plays repeatedly, false indicates repeated playback

<?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/girl_1 "        android:duration="/>     <item        android:drawable= "@drawable/girl_2"          android:duration= "/>    <item  "       android:drawable= "@drawable/girl_3"          android:duration= "/>    <item      "   android:drawable= "@drawable/girl_4"         android: duration= "/&GT;&NBSP;&NBSP;&NBSP;&NBSP"; <item        android:drawable= "@drawable/girl_5"          android:duration= "/>    <item   "      android:drawable= "@drawable/girl_6"          android:duration= "/>    <item       "  android:drawable= "@drawable/girl_7"         android:duration= "400 "/>    <item        android:drawable=" @ Drawable/girl_8 "        android:duration="/>     <item        android:drawable= "@drawable/girl_9"          android:duration= "/>    <item  "        android:drawable= "@drawable/girl_10"         android:duration= " "/>    <item        android:drawable=" @ Drawable/girl_11 "        android:duration="/></ Animation-list>

Mainactivity.java

package com.example.frameanim;import android.app.activity;import  Android.graphics.drawable.animationdrawable;import android.os.bundle;import android.view.view;import  android.view.View.OnClickListener;import android.widget.ImageView;public class  Mainactivity extends activity {private imageview iv;private animationdrawable  mAnimationDrawable; @Overrideprotected  void oncreate (bundle savedinstancestate)  { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);iv =  (ImageView)   Findviewbyid (R.ID.IV); Iv.setbackgroundresource (R.drawable.girl); //  Set the XML animation resource to ImageView background manimationdrawable =  (animationdrawable)  iv.getbackground ();  //   Gets the animated iv.setonclicklistener of the settings (New onclicklistener ()  {@Overridepublic  void onclick ( VIEW&NBSP;V)  {if  (!manimationdrawable.isrunning ())  {manimationdrawable.start ();}  else if  (Manimationdrawable.isrunning ())  {manimationdrawable.stop ();}});}} 

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.