帧动画

动画的帧定义XML Res的anim下:

<?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/img_1"
        android:duration="100"/>
    <item
        android:drawable="@drawable/img_2"
        android:duration="200"/>
    <item
        android:drawable="@drawable/img_3"
        android:duration="300"/>
    <item
        android:drawable="@drawable/img_4"
        android:duration="400"/>
    <item
        android:drawable="@drawable/img_5"
        android:duration="500"/>
    <item
        android:drawable="@drawable/img_6"
        android:duration="600"/>

</animation-list>

主Activity:一个按钮一个imageview不说了



package com.example.frame;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {

    private ImageView iv;
   private AnimationDrawable animationDrawable;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	iv=(ImageView) findViewById(R.id.iv);
	iv.setBackgroundResource(R.anim.ani);
	animationDrawable=(AnimationDrawable) iv.getBackground();
    }

    @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 void click(View v) {
	animationDrawable.start();
    }
}



你可能感兴趣的:(帧动画)