Android Frame(逐帧动画)的使用

1、activity

package com.example.frametest;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.MessageQueue;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

	private TextView frameTest;
	
	@SuppressWarnings("static-access")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		frameTest = (TextView)findViewById(R.id.frameText);
		frameTest.setBackgroundResource(R.drawable.frame);//绑定Frame动画图形
		
        final AnimationDrawable drawable = (AnimationDrawable) frameTest.getBackground();
        
        getMainLooper().myQueue().addIdleHandler(new MessageQueue.IdleHandler() {			
			public boolean queueIdle() {
				drawable.start();//启动动画
				return false;
			}
		});
        
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
2、xml

<?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="200" />
    <item android:drawable="@drawable/girl_2" android:duration="200" />
    <item android:drawable="@drawable/girl_3" android:duration="200" />
    <item android:drawable="@drawable/girl_4" android:duration="200" />
    <item android:drawable="@drawable/girl_5" android:duration="200" />
    <item android:drawable="@drawable/girl_6" android:duration="200" />
    <item android:drawable="@drawable/girl_7" android:duration="200" />
    <item android:drawable="@drawable/girl_8" android:duration="100" />
    <item android:drawable="@drawable/girl_9" android:duration="100" />
    <item android:drawable="@drawable/girl_10" android:duration="100" />
    <item android:drawable="@drawable/girl_11" android:duration="100" />
</animation-list>
3、layout

<RelativeLayout 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"
    tools:context=".MainActivity" 
    >
    <TextView
        android:id="@+id/frameText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</RelativeLayout>

项目下载地址:

http://download.csdn.net/detail/u010885095/8880093



你可能感兴趣的:(frame)