KcYxA
KcYxA

Reputation: 243

Canvas Larger Than Screen

I am drawing a grid and I want it to be larger than the screen size so that a user can drag the screen left/right/up/down to get to the rest of the grid.

What is the best way to do that? I've tried drawing a larger bitmap to the canvas, but didn't get anywhere.

 protected void onDraw(Canvas canvas) {
       super.onDraw(canvas);

       Paint paint = new Paint();
       paint.setStyle(Paint.Style.FILL);
       paint.setColor(Color.WHITE);

       Bitmap testBitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
       canvas.drawBitmap(testBitmap, 0, 0, paint);

       canvas.drawPaint(paint);

       //other grid drawing code here
  }

Upvotes: 1

Views: 2345

Answers (2)

KcYxA
KcYxA

Reputation: 243

I used the View's scrollBy() method in the onTouch method of the Activity. It worked.

Upvotes: 1

Inua
Inua

Reputation: 51

You can probably use the canvas.translate(x, y) method. That will adjust the origin for your canvas in relation to the screen. So canvas.translate(10, 10) will make you canvas origin (0, 0) be at the point of (10, 10) on the screen. Use a negative translation to scroll the screen.

Upvotes: 0

Related Questions