I have made a canvas and I’m setting an image on it, but I want that image should be in the center of every screen. When I change the screen like tab, galaxy etc it should take size from itself. But with my below code I’m getting an image every time on the bottom right corner on the screen.
Here is my code:
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
this.w = w;
this.h = h;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap b = BitmapFactory.decodeResource(getResource(), R.drawable.north_india);
canvas.drawBitmap(b, w/2, h/2, mPaint);
}
Images are drawn from the top left corner. So you need to correct for the image dimensions.