像猎物应用程序的动画背景?

时间:2018-02-16 18:44:18

标签: android animation background

我想在猎物应用程序中创建一个动画背景:

GIF:

我尝试使用自制的Canvas类和android定时器:

画布类

  • 简单类扩展View
  • 使用android.graphics.Path(mPath)

功能:

public void drawCircle(float x, float y, float radius){
   mPath.addCircle(x, y, radius, Path.Direction.CW);
   invalidate();
}


@Override
protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawPath(mPath, mPaint);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);
}

活动类:

final Handler handler = new Handler();

TimerTask timertask = new TimerTask() {
   @Override
      public void run() {
         handler.post(new Runnable() {
            public void run() {
                        runOnUiThread(new Runnable() {
                            public void run() {
                                if(size > displayHeight*2 && size > displayWidth*2){
                                    canvasView.clearCanvas();
                                    size = 0;
                                    timer.cancel();
                                }
                                canvasView.clearCanvas();
                                canvasView.drawCircle(0, 0, size, Color.BLACK);
                                size+=10;
                            }
                        });
                    }
                });
            }
        };
timer = new Timer();
timer.schedule(timertask, 0, 10);

它起作用,但非常不规则并且有帧丢弃 请帮我找一个更好的解决方案!

1 个答案:

答案 0 :(得分:0)