views:

53

answers:

2

There is no problem with portrait mode but when i try my app on landscape mode it doesn't look how it should.What is general aproach to solve this problem.My first idea is replacing X and Y places.If i am on the right track how should i do this ? Should i use an if statement at the beginning of the onDraw() function and write entire same code twice (one for x,y and other is for y,x) ?

A: 

There should be no need for your to swap the X and Y coordinates in your drawing. By default, when apps are rotated, so are the coordinate systems.

Romain Guy
unfortunately there is need in my app maybe i am doing something wrong.When phone is rotated(to landscape mode) canvas is redrawn but it still draws like portrait mode and half of the the canvas won't show on the screen virtically and half of the screen is emtpty horizontally.
dirhem
Are you trying to handle orientation changes yourself?
Romain Guy
A: 

It sounds like you are specifying absolute widths and heights for your drawing calls. For instance, if you saved myWidth = 480 and myHeight = 800 early on, and do all your drawing this way, then when the device is rotated, those widths and height no longer apply.

I think the solution for you here is to listen to size changed callbacks and reset your idea of width and height accordingly. If you are drawing directly in a view, you want to override View.onSizeChanged().

Josh
Hi thanks for your answer.I am not using absolute width and height but i am drawing a bitmap and my canvas and as i said before half of the my bitmap is not showing because of the X,Y problem of the rotation.
dirhem
Then you need to draw that bitmap differently when the size of the View changes. Recreate it with a wider width and thinner height at the time onSizeChanged is called.
Josh