Android Question Wrong layout variant on phone

dafi

New Member
Licensed User
Longtime User
I am new to using B4A even though I've had it a while, so this might be something obvious I am missing...

I have developed a small app and want to load it on several different phones. The first is a Galaxy S2 which has a screen res of 480x800, so I created a layout variant for 480x800 portrait with scale 1. The second phone is a Galaxy Y Duos 320x240 and I created another variant.
When I download the app to the phones, the Y Duos uses the layout intended for the S2 and vice versa.

I thought that if a variant existed with the exact dimension for the phone, it would use that variant.

The app is running No Title and Full Screen.

What am I missing?

I am running an old version of B4A V3.15.
 

Troberg

Well-Known Member
Licensed User
Longtime User
I agree with NJDude as well. Code your app to scale for any size, and you'll never have to worry about variants. It's not hard, and after doing it a couple of time, it will become second nature.

I come from a Windows/Linux background, and for me, the entire thing with variant layouts just seems unnecessary. I've never made different form variants for Windows to accommodate for the user resizing the window, instead, I just scale the contents intelligently.

Example:

Say that I'm doing a typical web browser window, with some buttons top left, then URL text box and then the web page below and a status bar at the bottom. It's trivial to write something like:

B4X:
buttonBack.Left=0%x  'Put button at far left
buttonForward.Left=buttonBack.Right 'Put button next to previous button
buttonRefresh.Left=buttonForward.Right 'Put button next to previous button
textURL.SetLeftAndRight(buttonRefresh.Right, 100%x) 'Let the URL textbox span the rest of the width
panStatus.SetLeftAndRight(0%x, 100%x) 'Set status panel to span full width
panStatus.SetTopAndBottom(100%y-panStatus.Height, 100%y) 'Put it at the bottom of the screen, while preserving height
web.SetLeftAndRight(0%x, 100%x) 'Span full width
web.SetTopAndBottom(buttonBack.Bottom, panStatus.Top) 'Fill the available height between buttons and status bar

This way, it will resize intelligently. Sure, some cases are a bit more complex, but it's seldom difficult.
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
True, it's just my personal tast to do it in scripts. Easier to read for me.

Also, a more complicated example that really needed scripts would have been less clear as an example. I wanted it clean.
 
Upvote 0

dafi

New Member
Licensed User
Longtime User
Thanks for the responses guys. Clearly I have a bit to learn about variants, scaling and scripts.
 
Last edited:
Upvote 0
Top