Question

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) ?

Was it helpful?

Solution

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.

OTHER TIPS

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().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top