首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2012-09-28 
自己写的一个动画,包含自定义的动画set动画集内包含自定义的一个动画,和一个缩放动画。?这个是页面package

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

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

?

这个是页面

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. */@Overridepublic 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;@Overridepublic 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());}@Overrideprotected 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();}}

?

热点排行