Erel,
I have read the tutorials and examples and I don’t quite understand everything. My solution is to manually adjust for different screen resolutions and scales. By setting a panel to width = 100 in the designer, I then read the width of the panel when the app loads…if the new width is 150, then I know that the OS scaled the panel by 1.5 and I now know how to back that number out for my manual adjustments.
The manual adjustment works for me given the screens I am creating, I am not sure if it would suffice for every scenario.
Dpalmond,
My resizing routine will resize the views in my original layout (320 X 480 @ 160 dpi) to any other resolution based on the same relativity of these views in the original layout.
For example, if I have a panel1 that is setlayout (10, 10, 100, 100), then I resize that panel1 based on the scale of the new resolution size to my original (320 X 480) layout. So if my new device’s resolution is 500 X 700, then I resize my original panel1 views based on the following:
ScaleX = 500 / 320
ScaleY = 700 / 480
NewLeft = panel1.Left * scaleX
NewTop = panel1.Top * scaleY
NewWidth = panel1.Width * scaleX
NewHeight = panel1.Height * scaleY
Then panel1 new setlayout is (NewLeft, NewTop, NewWidth, NewHeight)
I make the above adjustment for all views by looping through every view in my activity (in Activity_Create). I also adjust the textsize of my labels by the scaleY (usually looks good).
If a device has 240 dpi, then I find that my original panel1 setlayout of (10,10,100,100) is automatically resized to (15,15,150,150). Therefore I reverse this adjustment and resort to my manual routine above.
This works for me, but you may find that the tutorials and other methods work better, I don’t understand them. I have many labels and panels on my screens (over 20 screens at that), this method looks good for the kind of app I am developing. Keep in mind that the original 480 / 320 (1.5) does not have the same ratio as 700 / 500 (1.4), so images may look skewed.
I have loaded almost every portrait resolution I could think of in the emulator for testing and everything resizes well. I have also tested on phones and Tablets with different dpi resolution. I had to go back in my code and resize the text scale factor for a few label views when the dpi was 240, but other than that, I am satisfied with the results.
For about 20 layouts and some 30+ views items (labels panels, button etc) for many of these layouts, I am only using one variant for each layout and my manual adjustments (about 60 lines of code). This seemed like the best way to go for me.
Also, I stated 320 X 480 above, however my original dimensions are 320 X 455, given by activity.height and activity.width.