工具类

import android.graphics.Camera;import android.graphics.Matrix;import android.view.animation.Animation;import android.view.animation.Transformation;/** * A 3D Flip Card for Android */public class FlipCardAnimation extends Animation {    private final float mFromDegrees;    private final float mToDegrees;    private final float mCenterX;    private final float mCenterY;    private Camera mCamera;    //用于确定内容是否开始变化    private boolean isContentChange = false;    private OnContentChangeListener listener;    public FlipCardAnimation(float fromDegrees, float toDegrees,                             float centerX, float centerY) {        mFromDegrees = fromDegrees;        mToDegrees = toDegrees;        mCenterX = centerX;        mCenterY = centerY;    }    ////用于确定内容是否开始变化  在动画开始之前调用    public void setCanContentChange(){        this.isContentChange = false;    }    @Override    public void initialize(int width, int height, int parentWidth, int parentHeight) {        super.initialize(width, height, parentWidth, parentHeight);        mCamera = new Camera();    }    @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {        final float fromDegrees = mFromDegrees;        float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);        final float centerX = mCenterX;        final float centerY = mCenterY;        final Camera camera = mCamera;        final Matrix matrix = t.getMatrix();        camera.save();        if (degrees>90 || degrees<-90){            if (!isContentChange){                if(listener!=null){                    listener.contentChange();                }                isContentChange = true;            }            if (degrees>0) {                degrees = 270 + degrees - 90;            }else if (degrees<0){                degrees = -270+(degrees+90);            }        }        camera.rotateX(degrees);        camera.getMatrix(matrix);        camera.restore();        matrix.preTranslate(-centerX, -centerY);        matrix.postTranslate(centerX, centerY);    }    public void setOnContentChangeListener(OnContentChangeListener listener) {        this.listener = listener;    }    public interface OnContentChangeListener{        void contentChange();    }}

调用方法

private void startAnimation(FlipCardAnimation animation, View view) {        if (animation != null) {            animation.setCanContentChange();            view.startAnimation(animation);        } else {            int width = view.getWidth() / 2;            int height = view.getHeight() / 2;            animation = new FlipCardAnimation(0, 180, width, height);            animation.setInterpolator(new AnticipateOvershootInterpolator());            animation.setDuration(3000);            animation.setFillAfter(false);//            animation.setRepeatCount(-1);       //循环翻转            animation.setAnimationListener(new Animation.AnimationListener() {                @Override                public void onAnimationStart(Animation animation) {                }                @Override                public void onAnimationEnd(Animation animation) {                }                @Override                public void onAnimationRepeat(Animation animation) {//                    ((FlipCardAnimation)animation).setCanContentChange();   //循环翻转                }            });            view.startAnimation(animation);        }    }

第一个参数的工具类 第二个是view

更多相关文章

  1. android代码实现ScaleAnimation动画(附原码)
  2. 为Android写的WebService调用组件
  3. android java 调用 .so 动态库实例
  4. android 中遇到的空指针异常
  5. android 开机启动
  6. 【android】通话录音 -- service
  7. 浅析android下如何通过jni监控wifi网络连接、dhcpcd执行和power
  8. Android学习札记18:Drawable中的setDither()方法
  9. Android(安卓)WebView

随机推荐

  1. Android(安卓)Studio中设置ButterKnife、
  2. android panellistview 圆角实现代码
  3. Android如何在java代码中设置margin
  4. suse linux android sdk 下载.安装.配置
  5. 安卓巴士Android开发神贴整理
  6. android 状态栏 时间 错误 adb连接
  7. Android(安卓)Studio 初体验
  8. android 自定义attr 详解
  9. Android内存管理、监测剖析
  10. android平台解析epub--epublib