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
2010-10-11 17:06:36
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
2010-10-11 22:38:05
Are you trying to handle orientation changes yourself?
Romain Guy
2010-10-12 02:44:29
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
2010-10-12 15:37:06
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
2010-10-12 17:29:26
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
2010-10-12 22:57:46