u010885095的专栏

android探索

Android Frame(AnimationDrawable 逐帧动画)的使用

1、关键实现代码

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
个人分类: 安卓
上一篇安卓getSystemService
下一篇Android Studio 编译Gradle提示编码错误
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭