首页 > 解决方案 > Android椭圆轨道动画

问题描述

我将它用于椭圆路径中的轨道视图,但我的问题是当视图到达中间时速度有点慢!

public class morbit extends Animation {

    @Override
    public boolean willChangeBounds() {
        return true;
    }

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

        float degg = interpolatedTime * 360;
        float angleDeg = (degg) % 360;
        double sino = Math.sin(degg * Math.PI / -180);
        sino= Math.abs(sino);
        double coso = Math.cos(degg * Math.PI / -180);
        coso= Math.abs(coso);

        double rrr = 40 + (sino * 150);

        float angleRad = (float) Math.toRadians(angleDeg);
        angleRad = angleRad;

        float y = (float) (40 * Math.cos(angleRad));
        float x = (float) (rrr * Math.sin(angleRad));

        t.getMatrix().setTranslate((float)x, (float)y);    
    }
}

. . .

morbit an = new morbit();
an.setDuration(6000);
an.setRepeatMode(Animation.INFINITE);
an.setRepeatCount(9999);
an.setInterpolator(new LinearInterpolator());

((ImageView) findViewById(R.id.dottx)).startAnimation(an);

我用过LinearInterpolator,但对我没有帮助。

标签: androidanimation

解决方案


我希望您不会仍然坚持这一点,但对于其他任何人,请尝试交换:

sino and coso for

double sino =Math.sin(Math.PI + 200);

double coso = Math.cos(Math.PI + 400);

并将 rrr 换成

double rrr = 40 + (sino * 250);

我现在自己正在处理这个问题,所以我不太确定 interpolatedTime 的用途,尽管我猜它可以确保动画均匀分布。没有它,我似乎没有任何问题,所以也许这就是问题所在。


推荐阅读