简体   繁体   中英

Scaling Canvas to a screen size Java

Hiho. I am trying to set my canvas to fill the whole screen. I totally don't understand it's creation, cause I was taught to use 'lock' and 'unlockcanvasandpost' methods (in this way there is no constructor usage 'new Canvas'). With this code, this canvas is drew with borders with 'default color' - it just doesn't fit. I need from it to be exactly as the screen is. Here is the code, maybe someone will know, how to help :)

 private void drawGraphics() {

     canvas = surfaceHolder.lockCanvas();

    if( canvas == null)
        return;

    try{
        synchronized (surfaceHolder){
            actuallyDrawGraphics(canvas);
        }
    }finally {
        surfaceHolder.unlockCanvasAndPost(canvas);
    }
}

private void actuallyDrawGraphics(Canvas canvas) {
    canvas.drawColor(Color.RED);

    drawAButton(canvas);

    for(Ball ball : balls){


        canvas.drawBitmap(ballBitmap,
                -16 + (ball.x / 100f) * canvas.getWidth(),
                -16 + (ball.y / 100f) * canvas.getHeight(),
                paint
                );
    }

}

Im simply retarded - there was a padding on a Layout :)

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM