No matter, go first
Code: Only one activity
MainActivity: the code is very simple.
package com.animation.test;import zhuojin.lession15.animation.frame.R;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.view.View;import android.widget.ImageView;public class MainActivity extends Activity { ImageView img1=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); img1=(ImageView)findViewById(R.id.img1); } AnimationDrawable anim=new AnimationDrawable(); public void startBtn(View v) { for(int i=0;i<8;i++) { anim.addFrame(this.getResources().getDrawable(R.drawable.walk1+i), 100); } anim.setOneShot(false); img1.setBackgroundDrawable(anim); if(anim.isRunning()) { anim.stop(); }else { anim.stop(); anim.start(); } }}
Code structure
There is a movie girl. xml file in the drawbale folder. This file actually describes a frame rate for switching images. In fact, the implementation of 2D animation is the display of multiple images.
Registrant girl. xml
<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" > <item android:drawable="@drawable/walk1" android:duration="50" /> <item android:drawable="@drawable/walk2" android:duration="50" /> <item android:drawable="@drawable/walk3" android:duration="50" /> <item android:drawable="@drawable/walk4" android:duration="50" /> <item android:drawable="@drawable/walk5" android:duration="50" /> <item android:drawable="@drawable/walk6" android:duration="50" /> <item android:drawable="@drawable/walk7" android:duration="50" /> <item android:drawable="@drawable/walk8" android:duration="50" /></animation-list>
It's speechless. How can I upload code in this blog Park ..