美文网首页Android基础问题
ZAxisCirclingAnimation--duang du

ZAxisCirclingAnimation--duang du

作者: 奈蜇 | 来源:发表于2018-03-28 11:32 被阅读0次

我们先看看苹果的一个摆动效果,就两个字酷炫。


苹果TV的选中效果

所以安卓能搞吗,答案是肯定的啦

import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
//Z轴画圆动画
public class ZAxisCirclingAnimation extends Animation {
    int centerX, centerY;
    Camera camera = new Camera();
    float range = 9f;
    @Override
    public void initialize(int width, int height, int parentWidth,
                           int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        //获取中心点坐标
        centerX = width / 2;
        centerY = height / 2;
        //动画执行时间  自行定义
        setDuration(4000);
        setInterpolator(new LinearInterpolator());
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        final Matrix matrix = t.getMatrix();
        camera.save();
        //放大时间
        float timeAmplifier;
        if (0 <= interpolatedTime && interpolatedTime <= 0.25f) {
            timeAmplifier = 4f * interpolatedTime;
            camera.rotateX( (float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range)));
            camera.rotateY( (float)Math.toDegrees(Math.asin(timeAmplifier/range)));
        } else if (0.25f < interpolatedTime && interpolatedTime <= 0.5f) {
            timeAmplifier = 4f * (interpolatedTime-0.25f);
            camera.rotateX( -((float)Math.toDegrees(Math.asin(timeAmplifier/range))));
            camera.rotateY( (float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range)));
        } else if (0.5f < interpolatedTime && interpolatedTime <= 0.75f) {
            timeAmplifier = 4f * (interpolatedTime-0.5f);
            camera.rotateX( -((float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range))));
            camera.rotateY( -((float)Math.toDegrees(Math.asin(timeAmplifier/range))));
        } else if (0.75f < interpolatedTime && interpolatedTime <= 1) {
            timeAmplifier = 4f * (interpolatedTime-0.75f);
            camera.rotateX( (float)Math.toDegrees(Math.asin(timeAmplifier/range)));
            camera.rotateY( -((float)Math.toDegrees(Math.asin((1f-timeAmplifier)/range))));
        }
        //把我们的摄像头加在变换矩阵上
        camera.getMatrix(matrix);
        //设置翻转中心点
        matrix.preTranslate(-centerX, -centerY);
        matrix.postTranslate(centerX, centerY);
        camera.restore();
    }
}

达到的效果:


安卓下的效果

额,怎么感觉很像有点不同呢.........
问题不大好吗 它的动作要领在线就行
---分割线---
------2018-03-29------最终效果实现。

托马斯回旋选中效果

备注:使用此动画的View记得开抗锯齿。

有一点要注意下,就是用阴影来对抗锯齿。这个旋转动画的锯齿太严重了, view做了抗锯齿也很严重。我突发奇想,锯齿的来源是绘制运动的直线导致的。我们让它边缘是很多的点那不就解决了。

相关文章

  • ZAxisCirclingAnimation--duang du

    我们先看看苹果的一个摆动效果,就两个字酷炫。 所以安卓能搞吗,答案是肯定的啦 达到的效果: 额,怎么感觉很像有点不...

  • bibibi

    du du du

  • Du-du-du-do it and cultivate you

    Ten thousands steps a day keeps myself away . Why ? Bec...

  • du

    破冰行动,我完完整整从头到尾追下来的一部剧。从最初的奔着黄景瑜的颜入坑,到每天陪我一起度过跑步的难挨时光。剧里演的...

  • du

    今天吃完午饭,老爸对我和姐姐说,咱仨斗地主吧?!明智的老爸没有邀请老妈,只邀请了我们姐俩儿。要知道,我们家已经很久...

  • Du

    有先哲说,人,生到世间来就是一场du。 有人向左有人向右,有人向东,偏有的人硬向西…总没有完全统一的时侯。这种不统...

  • 2017-11-30

    ha ru du du e l l l

  • 楞严咒速记6

    注音: nā mō pó qié pó dìnā mō emíduō pó yēduō tuō qiéduōyē ...

  • 但求往生

    往生咒 ná mó a mí duō pó yè duō tuō qié duō yè 南 无 阿 弥 多 婆 夜...

  • 但求往生

    往生咒 ná mó a mí duō pó yè duō tuō qié duō yè 南 无 阿 弥 多 婆 夜...

网友评论

    本文标题:ZAxisCirclingAnimation--duang du

    本文链接:https://www.haomeiwen.com/subject/pesycftx.html