⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frameanimationactivity.java

📁 Android从入门到精通
💻 JAVA
字号:
package com.androidbook.ShapeShifter;

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

public class FrameAnimationActivity extends Activity {
 
	AnimationDrawable mframeAnimation = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.framebyframe);
		
	     // Handle Start Button
		final Button onButton = (Button) findViewById(R.id.ButtonStart);
		onButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startAnimation();
			}
		});
			
		// Handle Stop Button
		final Button offButton = (Button) findViewById(R.id.ButtonStop);
		offButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				stopAnimation();
			}
		});
	    
	}
	
	private void startAnimation()
	{
		 ImageView img = (ImageView)findViewById(R.id.ImageView_Juggle);
		 
		 BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.splash1); 
		 BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.splash2); 
		 BitmapDrawable frame3 = (BitmapDrawable)getResources().getDrawable(R.drawable.splash3); 
		 
		 // Get the background, which has been compiled to an AnimationDrawable object.
		 int reasonableDuration = 250;
	     mframeAnimation = new AnimationDrawable();
	     mframeAnimation.setOneShot(false);	// loop continuously
	     mframeAnimation.addFrame(frame1, reasonableDuration);
	     mframeAnimation.addFrame(frame2, reasonableDuration);
	     mframeAnimation.addFrame(frame3, reasonableDuration);
	     
	     img.setBackgroundDrawable(mframeAnimation);
	     
	     mframeAnimation.setVisible(true,true);
	     mframeAnimation.start();
	}
	private void stopAnimation()
	{
		mframeAnimation.stop();
		mframeAnimation.setVisible(false,false);
	}
	

	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -