Reputation: 789
I got width and height of the screen by following code
WindowManager wm = ((WindowManager)context.getSystemService(context.WINDOW_SERVICE));
Display display = wm.getDefaultDisplay();
m_nDisplayWidth = display.getWidth();
m_nDisplayHeight = display.getHeight();
Shouldn't this code place my image in the middle of the screen?
canvas.drawBitmap(m_circle1, (m_nDisplayWidth/2),(m_nDisplayHeight/2), null);
My image is located near the right corner.
Any help would be appreciated!
Upvotes: 1
Views: 248
Reputation: 56
you can use
canvas.drawBitmap(m_circle1, (m_nDisplayWidth - m_circle1.getWidth()) / 2,(m_nDisplayHeight - m_circle1Height()) / 2, null);
Upvotes: 0
Reputation: 6335
Use below code for placing image in center.
canvas.drawBitmap(m_circle1, (m_nDisplayWidth/2 - imageWidth/2),(m_nDisplayHeight/2 - imageHeight/2), null);
where imageWidth
is width of your image and imageHeight
is height of your image.
Upvotes: 4