Layout Variants loading criteria

bloxa69

Active Member
Licensed User
Longtime User
Erel, you've suggested starting a new thread with that, so here we go:

I have a problem loading correct layout variants. To be short, if I don't have a specific variant for the device I'm testing, the app will always pick the smallest variant I have in the layout file, like 320x480.
I don't know, may be it's by design; I searched the tutorials and posts but couldn't find any info on how b4a picks the layout variant if it cannot find a matching set.

Example: I have the following variants: 800x1280/1280x800, 600x1024/1024x600, 320x480/480x320 all in one layout file, all scale 1. When device's screen is exact match, it's fine, it picks the right layout variant. But if I load the app on 1440x900 screen, it picks 480x320 layout, though logically the best match would be 1280x800. Same thing about let's say 1280x720 (i use this size on my hardware accelerated VM simulator to capture apps' promo videos at 720p) - it picks 480x320 instead of much closer 1024x600 variant.

quoting Erel:

The variants you wrote have no meaning without the scale value.

my answer:

They are all scale 1 as you suggested in your tutorial. I'm not at my location, so I cannot upload the layouts, but they are nothing special and they work fine. In most cases i just AutoScaleAll and center the elements or specify the background size, like element.width = 100%x etc. The layouts work fine, that's not a problem. The problem is it's not clear (to me) how B4A chooses the variants when loading the layout. I've tried to find the answer in your tutorials and other tutorials but couldn't, may be I'm overlooking something.

I really need different layouts for phones versus tablets, so I cannot just use one layout and autoscale it then move the elements around a bit for different screens. I would also prefer to have it all in one layout file with variants, not creating different layout files for phones and tablets and then check the screen size in the script and load different layouts based on the device's screen size. Please advise.

(Your Layout Designer is great and helps me a lot with my projects. Thank you.)
 

bloxa69

Active Member
Licensed User
Longtime User
Erel,
thanks for your help. Today I've managed to fix errors I was getting on 2.3 Beta when loading layouts into a panel, so I could do better testing. In 2.3 layout variants work better (for me) than in 2.2. As you mentioned
A device with a screen resolution of 1440x900, scale = 1 should pick the 1280x800, scale = 1 variant.

It works as expected now for me in 2.3. There are two things though that I'm still at loss with:

1. When I delete 1024x600x160 variant and only leave 1280x800x160 and 480x320x160 variants and then load the app on 1024x600x160 test screen, it picks 480x320x160 variant though I think 1280x800x160 is closer to the target screen.

2. When I delete all smaller variants and only leave two (vertical and horizontal) HD variants - 800x1280x160 and 1280x800x160, and then load the app on (smaller) 1024x600x160 screen (landscape) it picks the portrait variant (not landscape) and doesn't scale anything down though I have AutoScaleAll in the layout script.

So, after spending quiet some time on all those variants and testing I got the feeling I'd have to follow your advice from tutorials and stick to just one layout variant as a base and then to move, reposition and scale all elements as needed programmatically - in the end it will take less time then creating variants. And maintaining and updating it might be easier.

The only problem I see - in that case I'll have to work on a 320x480x160 layout and that's too tiny for my layouts. I mean, I've tried to use larger variants as a base but they don't scale down, only up, so one have to specify the size for each element in the script in dips or %x or %y. As a second thought, your new IF ... THEN option in 2.3 Layout Designer might help to specify different AutoScaleRate for different screens (I've tried negative numbers for it and it works for scaling down). I'm not sure though one can check the screen size from the Designer script.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. As the large variant is significantly larger than the target device, the smaller variant is chosen. Otherwise some of the views will not be visible.

2. Not sure why portrait variant is chosen in that case. Need to investigate it.

AutoScale always scales based on the device target size compared to the 4" phone size. You should not use it if your variant already takes care of increasing the views size and text size.

I recommend you to see this example:
Example of an app with a phone and tablet layouts

ActivitySize keyword allows you to get the activity size (which is similar to the screen size).
 
Upvote 0

bloxa69

Active Member
Licensed User
Longtime User
Erel, thanks for example of an app with a phone and tablet layouts.

The new UI Cloud service is very useful for such tasks.

No doubt about the Cloud testing - nothing is better than a real device and that's a great new feature, I will definitely use it for final checks. For now I am using AndroVM (former Buildroid) + VirtualBox + AndroVMPlayer combination with hardware acceleration and it kicks *ss. The speed is unbelievable and I can run it at any size I want. In some cases, when the emulator window is <= 1024x600, it's faster than actual device, it just flies. Deploying the app to this virtual Android Box is faster than to an actual hardware device, I am serious. I have a couple of tablets and phones, but I ended up doing most of the development work on AndroVM emulator and only using the hardware devices for final checks.

Android SDK emulators just suck, it's such a pain, I think you know what I'm talking about. That thing saved my day - I have a lot of HD images and complicated layered layouts.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…