自己写的一个动画,包含自定义的动画set_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > 自己写的一个动画,包含自定义的动画set

自己写的一个动画,包含自定义的动画set

 2010/11/29 9:13:45  hellorheaven  http://hellorheaven.javaeye.com  我要评论(0)
  • 摘要:动画集内包含自定义的一个动画,和一个缩放动画。这个是页面packagecom.nico;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.animation.AnimationSet;importandroid.view.animation.ScaleAnimation;importandroid.widget.ImageView
  • 标签:自定义

动画集内包含自定义的一个动画,和一个缩放动画。

?

这个是页面

package com.nico;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

public class AnimationActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ImageView img = (ImageView) findViewById(R.id.img);
		AnimationSet ani = new AnimationSet(false);
		ani.addAnimation(new MoveAnimation());
		ScaleAnimation scale = new ScaleAnimation(1.5f, 1.0f, 1.5f, 1.0f);
		scale.setDuration(5000);
		scale.setFillAfter(true);
		ani.addAnimation(scale);
		ani.setDuration(5000);
		ani.setFillAfter(true);
		// ani.start();
		img.startAnimation(ani);

		ani.start();
	}
}

?这个是自定义动画:

package com.nico;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;

public class MoveAnimation extends Animation {

	private int halfWidth;

	private int halfHeight;

	private Camera camera;

	@Override
	public void initialize(int width, int height, int parentWidth,
			int parentHeight) {

		super.initialize(width, height, parentWidth, parentHeight);
		setDuration(5000);
		setFillAfter(true);

		halfWidth = width / 2;
		halfHeight = height / 2;
		setInterpolator(new LinearInterpolator());

	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {

		camera = new Camera();
		camera.save();
		final Matrix matrix = t.getMatrix();

		System.out.println("------------------->" + interpolatedTime);
		camera.translate((100.0f * interpolatedTime) ,
		 (150.0f * interpolatedTime - 150) , 0.0f);
		camera.rotateY(45 * (interpolatedTime));
		camera.getMatrix(matrix);

		// matrix.preScale(interpolatedTime, interpolatedTime);
		// matrix.preRotate(interpolatedTime * 360);
		matrix.preTranslate(-halfWidth, -halfHeight);
		matrix.postTranslate(halfWidth, halfHeight);

		camera.restore();
	}
}

?

发表评论
用户名: 匿名