Android Question Problem loading a layout variant on some devices

DavideV

Active Member
Licensed User
Longtime User
Hi, this is my first post and english isn't my native language so sorry for it .
I'm tryng to port an app i wrote with another language into B4A and developing was faster and simple until i found this problem:
first of all i'm using B4A 3.20 release (project started with b4a 320 beta), i created the layout with a 7'' tablet connected to the designer
There is only 1 layout with 2 variant : one for portrait ( 480x800 dip) and one for landscape (800x 480 dip), some views are in different positions depending on the variant. The software is responsible for scaling/hide/show all views based on device display size, scale and rotation. Testing the layout on various of my devices it load correctly on all of them in portrait variant but when i rotate the device the landscape variant isn't loaded. In the log i can see the display height & width changed but the views sizes are the same of the portrait layout. I thought about my mistake in program but the strange thing is that on 2 tablet with different resolution i get the expected layout variant based on rotation and in all my phones i can get right variant only for portrait as you can see in the images. I also add the source if someone can try/help...
Thank to the great B4A community in advance
DavideV
 

Attachments

  • blueremote 2014-01-19 1600.zip
    blueremote 2014-01-19 1600.zip
    204.1 KB · Views: 276
  • phone 540x960.png
    phone 540x960.png
    147.7 KB · Views: 427
  • phone 940x560.png
    phone 940x560.png
    76.2 KB · Views: 386
  • tablet 600x1024.png
    tablet 600x1024.png
    165.1 KB · Views: 427
  • tablet 1024x600.png
    tablet 1024x600.png
    125.3 KB · Views: 448
Why do you scale the views with this code? Why don't you call AutoScaleAll instead in the designer script?

1. It is a mistake to load the layout to a panel before adding the panel to its parent (there should be a warning at runtime about this).
2. You can check the loaded variant with: Log(MyLayout.LoadLayout(...))
3. Once you move the layout handling to the designer, you will also be able to see how it scales by sending it to the UI Cloud.
 
Upvote 0
Hi Erel, thx you for the quick response :)
scaling views in code allow the user to select the graphics to fit the entire display (for better use) or fit the display proportional (for better look, mostly used with big displays), you can see under 'menu' > best fit mode > select fit or proportional.

1) i'm sorry but i can't understand, can you point me to wrong code/ how to?
i tried to remove the routine that load the layout to the panel and load the layout directly to the activity but result is same.
2) nice, i will try
3) i will try it too

thx again
 
Upvote 0
Ok, i added Log(MyLayout.LoadLayout(...)) and i can confirm that on phones only the portrait variant is loaded while on tablet the variant change accordling to the orientation ( see logs ).
Sending to the cloud is same: variant is correct only on tablets...
I'm confused.... what's wrong?

About warnings , there are some about views , see screenshot.
why some views added by the designer are not initialized and other yes?

Sorry for all questions, i need to understand in order to proceed with my app :)
Thx again.
DavideV
 

Attachments

Upvote 0
As the two variants are very different it makes sense to break this layout into two layout files. It is simple. You just need to save the layout file with a different name and remove one of the variants. This will give you complete control over the layout.

In your case you need to accurately match the views position to the background image. This means that you need to use percentage for all of the dimensions. I still recommend you to use the designer script for that. It will be easier to test it.
 
Upvote 0
Thk you Erel,
i did the two layouts and it worked.
Thk for the tips about scaling too but for this project i need exact coordinates in pixel and the 'dip' scaling does the job :)
 
Upvote 0
Back
Top