zoukankan      html  css  js  c++  java
  • Android 图片转动效果(一)

    我们先来看看效果图:

    <ignore_js_op>190302td1aajjrtgddurnt.jpg

    <ignore_js_op>1903047yc2vg49ycpqpc4x.jpg


    看见效果就是旋转前和旋转后的效果

           如果是你想要的效果,那么继续往下看,如果不是,那可以跳过了。这是一个动画,而不是用matrix实现的直接翻转图片。
           我这个是根据APIDemo,简单修改写的需要一个Rotate3d,类,继承,Animation这个类可以直接拷过去,不用做任何的修改。其中的方法自己找相关资料研究。

    java代码:

    public class Rotate3d extends Animation{ 

     

    private final float mFromDegrees; 

     

    private final float mToDegrees; 

     

    private final float mCenterX; 

     

    private final float mCenterY; 

     

    private final float mDepthZ; 

     

    private final boolean mReverse; 

     

    private Camera mCamera; 

     

    public Rotate3d(float fromDegrees, float toDegrees, float centerX, float centerY, float depthZ, boolean reverse) { 

     

    mFromDegrees = fromDegrees; 

     

    mToDegrees = toDegrees; 

     

    mCenterX = centerX; 

     

    mCenterY = centerY; 

     

    mDepthZ = depthZ; 

     

    mReverse = reverse; 

     

     

    @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 (mReverse) { 

     

    camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime); 

     

    } else { 

     

    camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime)); 

     

     

    camera.rotateY(degrees); 

     

    camera.getMatrix(matrix); 

     

    camera.restore(); 

     

    matrix.preTranslate(-centerX, -centerY); 

     

    matrix.postTranslate(centerX, centerY); 

     

     

    复制代码

     

     
  • 相关阅读:
    跟王千问学数学之什么是比
    王千问之学习的金字塔
    跟王千问学数学之平方差公式
    跟王千问学数学之三角形
    跟王千问学数学之小数加法、最小公倍数
    跟王千问学数学之小数
    一年级孩子的特点以及如何辅导他们学习
    python中的property属性
    python中的浅拷贝和深拷贝
    http协议、web服务器、并发服务器(下)
  • 原文地址:https://www.cnblogs.com/greywolf/p/2826364.html
Copyright © 2011-2022 走看看