Here are a few tips I have gleaned while upgrading my app to accommodate the range of screens with resolutions from 218 to 280 px .
Here's a fairly complex target screen. It has around 15 elements that needed to be aligned vertically and horizontally.
- View the screen through a grid not pixels. During layout, overlay the screen with a grid. Depending on the complexity of the screen the grid could be a simple as 3 x 3, or, for a more complex screen like this, I used 20 x 20 to do the fine adjustments.
dc.setPenWidth(1);
dc.setColor(0xFFFFFF, 0xFFFFFF);
var grid = 20;
for (var i=1; i< grid; i+=1){
dc.drawLine (0, screenHeight*i/grid, screenWidth, screenHeight*i/grid);
dc.drawLine (screenWidth*i/grid, 0, screenWidth*i/grid, screenHeight);
}
- Note that the fonts are scaled to the screen, so, for example, FONT_SYSTEM_SMALL takes the same proportion of the screen height and width on a Fenix5S with 218 px as it does on a Fenix6X Pro with 280 px.
- The origin of text positioning is the top left corner of the text, so to visualize the way the text is being positioned during layout, set the background color of the fonts to grey (0x555555) .
- Use getFontHeight() to align the text to the middle of a grid line vertically. So, to align your text (like "LINE: 04..." above) to the middle of say, the 8th grid line from the top, use screenHeight*8/grid + Gpx.getFontHeight(Gpx.FONT_SYSTEM_SMALL)/2
- Use getFontAscent() to align the base of different fonts to a grid line (like "4 m" above). This is the distance from the origin to the base of the number or upper case characters in the font. So, to align different fonts along say, the second grid line from the top use screenHeight*2/grid + Gpx.getFontAscent(Gpx.FONT_SYSTEM_SMALL)/2