screen sizes question

Cor

Active Member
Licensed User
Longtime User
It's not clear to me how to make a program which fits
automatically to the following screen sizes.

portrait layout

240x400
320x480
400x800

I designed my main prog for 320x480

Must I manually detect scale on the device and adjust view positions and images?

There must be an easier way, to automatically scale

advice is needed

grCor
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
As I wrote in the post mentioned above Basic4android does scale layouts automatically.
However developers are sometimes confused with the meaning of auto scale. Auto scale means that the layout is scaled based on the screen DPI - dots per inch. The ratio between the height and the width always stays the same. So if one device is longer than the other there will be an empty space at the bottom.

The same layout can be used for a device with HVGA device with 320*480 (160DPI = 1.0) and WVGA device with 480*800 (240DPI = 1.5). Though you will have some empty space at the bottom.
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
A typo there I think Erel.
The same layout can be used for a device with HVGA device with 320*480 (160DPI = 1.0) and WVGA device with 480*800 (240DPI = 1.5).
But it won't scale on a device like my tablet with 480*800(160DPI = 1.0) so you need a separate layout to cope with this.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It shouldn't be difficult to create layout variants for many types of screens.
- Create emulators with the required screen resolutions.
- Design the first layout with the regular settings.
- Add layout variants for each target resolution. Connect to the matching emulator and move the views as required.

- If you later add a new view you will need to set its position in all variants. Therefore it is recommended to first create the "main" layout and only then add the variants.
 
Upvote 0

colin9876

Active Member
Licensed User
Whats the command to get the screen height and screen width of the device that the codes running on?
does canvas1.height return the value? (just a guess?)
 
Upvote 0

Cor

Active Member
Licensed User
Longtime User
B4X:
Dim layoutVal As LayoutValues

 layoutVal=GetDeviceLayoutValues
 If layoutVal.width < 320 Then
    splashPanel.SetBackgroundImage(LoadBitmap(File.DirAssets,"notsupported.png"))
   Activity.AddView(splashPanel, 0, 0, 100%x, 100%y)
   Return True
 End If

grCor
 
Upvote 0
Top