How about virtual layouts

straybullet

Member
Licensed User
Longtime User
I use other tools for Android Apps (Shiva 3d , Unity 3d, Corona) and you do not have to do all these layout variants which work correctly half the time anyways.

Is there a way just to create 1 layout and have it scale/zoom to fit the screen? Providing you fix the orientation to landscape / portrait and B4A will do best effort scaling.

I have having a nightmare with the designer not matching my devices. I have 6 Android devices I use for testing and rarely does the designer match the device. 3 of the devices are 480 x 800 and each one displays the 480 x 800 layout differently.


Its not just 1 layout either, its any thing I do with the designer.
 

straybullet

Member
Licensed User
Longtime User
Ok here's a question, if one device is a dpi of 160 and the other 240 but both are 480 x 800, how do I create a variant for the 480 x 800 240 dpi?


Also the devices I am using to test...

Dell Streak 5 (5" phone/tablet)
Dell Streak 7 (7" tablet)
LG G2X
(2) Samsung Sidekick 4gs
Acer Icona 501 (10" tablet)
HTC Aria
HTC Wildfire

Blackberry Playbook (7" tablet) in Android mode (but I don't care if things work on this too much, I focus on the real Androids)


First check the two examples I referred you to.

What is the types of your three Android devices (phone, tablet)?
 
Last edited:
Upvote 0

straybullet

Member
Licensed User
Longtime User
The LG G2X seems to be the correct display (larger text) etc, but the Streak 5 has small text and the whole design is smaller, where as I designed it to fill the screen for 160, the Streak is it about 1/2 the correct size. This is odd because you would think the 240 dpi device would be the smaller one if any.

-- So I did some testing and the G2X (the newer phone) is using the 320 x 480 layout (why I do not know) and the streak is using the correct one 480x800 which both phones are.

For some reason b4a on the g2x is deciding to use a smaller layout than it screen really is is. Any suggestions to fix this?

Thanks


You should just ignore the high scale devices. Their physical size is similar to the standard phone layout. Do not create a special variant for them.

The standard variant will work properly.
 
Upvote 0

straybullet

Member
Licensed User
Longtime User
Erel thanks I will do it , but why?

I mean if you have the screen real estate why not use it? I am not grasping why we have variants I guess.
 
Upvote 0

William Hunter

Active Member
Licensed User
Longtime User
Layouts

@straybullet - It's most likely that misplacement of objects would be minimal. I had a similar problem in managing the height of a ScrollView. In my case, because of the layout, %y could not remain constant, in order to have compatibility with a number of devices having various screen resolutions and density. I managed the differing % value on the y-axis by using the following code in Activity_Create. This has its limitations, in that it doesn’t provide layout compatibility over all devices. I chose five of the more common screen variations for inclusion. I hope this helps.

Dim LayoutVal As LayoutValues (Declared as Global)

Regards
B4X:
LayoutVal = GetDeviceLayoutValues
Dim Dens As Float   
Dens = Density
'Log("Density = " & Dens) ' debug
If Activity.Width > Activity.Height Then
   If LayoutVal.Width = 1280 AND Dens = 1 Then
      svHeight = 90%y
   Else If LayoutVal.Width = 1280 AND Dens = 1.5 Then
      svHeight = 85%y
   Else If LayoutVal.Width = 800 AND Dens = 1 Then
      svHeight = 81%y
   Else If LayoutVal.Width = 800 AND Dens = 1.5 Then
      svHeight = 70%y
   Else If LayoutVal.Width = 480 AND Dens = 1 Then
      svHeight = 70%y
   Else
      Msgbox("MailPurge is not compatible with this device ...", "Sorry")
      ExitApplication
   End If
Else If Activity.Width < Activity.Height Then
   If LayoutVal.Width = 800 AND Dens = 1 Then
      svHeight = 95%y
   Else If LayoutVal.Width = 800 AND Dens = 1.5 Then
      svHeight = 90%y
   Else If LayoutVal.Width = 480 AND Dens = 1 Then
      svHeight = 89%y
   Else If LayoutVal.Width = 480 AND Dens = 1.5 Then
      svHeight = 88%y
   Else If LayoutVal.Width = 320 AND Dens = 1 Then
      svHeight = 86%y
   Else
      Msgbox("MailPurge is not compatible with this device ...", "Sorry")
      ExitApplication
   End If
End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Erel thanks I will do it , but why?
Because the physical difference between 320x480, scale=1 ("standard") to 720x1184, scale=2 (Galaxy Nexus) is small.
The Nexus is just an example. The same is true to all phone devices.

You should "normalize" the dimensions. Galaxy Nexus normalized dimensions are: 360x592, scale=1. So the Nexus is a bit longer and wider.

It is easier to compensate these differences with the designer script.

I definitely don't recommend you to use a code as posted in the above post.

I plan to create a new thread with a collection of layout tips and best practices.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Hello Erel – I know my knowledge of B4A is not at the level of yourself and other senior contributors to this forum, but the ScrollView is one control that cannot be created in the Designer, and then populated without being first declared, initialized and then added with Activity.AddView.

This is not true. Of course you can add a ScrollView with the designer without any problems. You can even create a layout for the content of the scrollview which can then be loaded by ScrollView.Panel.Loadlayout().

The designer with the designer scripts is very powerful and using it right you don't have to fiddle around with %-values in your B4A code. The only drawback of the designer layouts is that loading them is quite slow. So if you have many identical panels (10 or more) on one activity it is better to fill them by code than with LoadLayout(). Otherwise it may take some seconds to initialize your activity.
 
Upvote 0
Top