android图像动画怎么做

前端之家收集整理的这篇文章主要介绍了android图像动画怎么做 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试进行简单的图像动画处理.我想使它看起来好像直升机的螺旋桨叶片正在转动.我有3幅直升机图像,并且根据动画进度显示这些图像之一.问题是所有三个图像最终都彼此重叠,而不是一次显示一个图像,从而创建了动画.这是我到目前为止所做的,我什至尝试通过执行canvas.drawColor(Color.BLACK)来清除画布,但这会清除整个画布,这不是我想要的.

这就是我所拥有的:

1)在View类中:

静态类直升机{
        专用长mLastUpdate;
        private long mProgress = 0;
        私人最终流通量mX;
        私人最终流通量

    private final Bitmap mHelicopter1;
    private final Bitmap mHelicopter2;
    private final Bitmap mHelicopter3;
    private final float mRadius;

    Helicopter(long mLastUpdate,float mX,float mY,Bitmap helicopter1,Bitmap helicopter2,Bitmap helicopter3) {
        this.mLastUpdate = mLastUpdate;
        this.mX = mX;
        this.mY = mY;
        this.mHelicopter1 = helicopter1;
        this.mHelicopter2 = helicopter2;
        this.mHelicopter3 = helicopter3;
        mRadius = ((float) mHelicopter1.getWidth()) / 2f;

    }

    public void update(long now) {
        mProgress += (now - mLastUpdate);

        if(mProgress >= 400L)
        {
         mProgress = 0;
        }
        mLastUpdate = now;
    }

    public void setNow(long now) {
        mLastUpdate = now;
    }

    public void draw(Canvas canvas,Paint paint) 
    {       

        if (mProgress < 150L) 
        {
            canvas.drawBitmap(mHelicopter1,mX - mRadius,mY - mRadius,paint);
        } 
        else if (mProgress < 300L) 
        {
            canvas.drawBitmap(mHelicopter2,paint);

        } 
        else if(mProgress < 400L)
        {
         canvas.drawBitmap(mHelicopter3,paint);
        }

    }

    public boolean done() {
        return mProgress > 700L;
    }
}

private ArrayList<Helicopter> mHelicopters = new ArrayList<Helicopter>();

2)这在线程的run()中被调用

private void doDraw(Canvas canvas) 
    {
     final long now = SystemClock.elapsedRealtime();

        canvas.save();

        for (int i = 0; i < mHelicopters.size(); i++) {
            final Helicopter explosion = mHelicopters.get(i);
            explosion.update(now);
        }

        for (int i = 0; i < mHelicopters.size(); i++) {
            final Helicopter explosion = mHelicopters.get(i);
            explosion.draw(canvas,mPaint);
        }

        canvas.restore();
    }

有人能帮我吗?我看了很多有关动画的网络示例,它们似乎总是涉及文本,而不涉及图像.谢谢.

最佳答案
通常,绘制画布的线程会重绘整个画布以及所有道具/演员.这样,如果您增加直升机叶片图像索引,它将在其余画布重新绘制后被绘制到位.诸如此类的东西:Background-> Helicopter-> Blade1下一次迭代Background-> Helicopter-> Blade2.
原文链接:https://www.f2er.com/android/531488.html

猜你在找的Android相关文章