Animations for Android

Source: Internet
Author: User

Implementing frame-wise animation
Implementing tweened Animations

One-frame animation
New Android Project

New layout layouts

<linearlayout 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:background= "@animator/fox"
Android:id= "@+id/main_rl"
Tools:context= ". Mainactivity ">

<imageview
Android:layout_width= "Match_parent"
android:layout_height= "308DP"
android:src= "@drawable/ic_launcher"/>

</LinearLayout>

Create a new animation file under the resource Res file animator code as follows drawable-hdpi put photos under Res file

<?xml version= "1.0" encoding= "Utf-8"?>
<animation-list xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:drawable= "@drawable/a1" android:duration= "/>"
<item android:drawable= "@drawable/a2" android:duration= "/>"
<item android:drawable= "@drawable/a3" android:duration= "/>"
<item android:drawable= "@drawable/a4" android:duration= "/>"
<item android:drawable= "@drawable/a5" android:duration= "/>"
<item android:drawable= "@drawable/a6" android:duration= "/>"
<item android:drawable= "@drawable/a7" android:duration= "/>"
</animation-list>

New Activity Java class

Package com.example.android_lession9_1;

Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.os.Message;
Import android.app.Activity;
Import android.graphics.drawable.AnimationDrawable;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.LinearLayout;
Import Android.widget.RelativeLayout;

public class Mainactivity extends Activity {

Private LinearLayout RL;
Boolean flag=false;
Private MyHandler my;
Animationdrawable ANI;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Rl= (LinearLayout) Findviewbyid (R.ID.MAIN_RL);
My=new MyHandler ();
Ani= (animationdrawable) rl.getbackground ();
Rl.setonclicklistener (New Onclicklistener () {
//
@Override
public void OnClick (View v) {
Start animation
Get animation files
Animationdrawable ani= (animationdrawable) rl.getbackground ();
Flag=!flag;
if (flag) {
Ani.start ();
}else{
Ani.stop ();
//            }
//
//
//            }
//        });

Ani.start ();
New Thread (New Runnable () {

@Override
public void Run () {
My.sendemptymessage (0);
}
}). Start ();




}

@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.main, menu);
return true;
}




public class MyHandler extends handler{

@Override
public void Handlemessage (Message msg) {

Ani.start ();
Super.handlemessage (msg);
}
}

}

Animations for Android

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.