Android Question A never asked question: layouts scaling ^_^

LucaMs

Expert
Licensed User
Longtime User
[Just pour parle . Note that here now is 3:40 AM ! So, I'm sleeping ].


I almost abandoned the idea of using only the Designer and its scripts.

So, I was developing a small project with the intention of use code later to scale the layout.

Just out of curiosity, I wanted to look at the effect of Designer' AutoScaleAll only, on two different devices.

I had not ever done!

Let's see if I can explain the facts.


I have created a Variant which has the size and the density of my smartphone. Then: (Landscape - Full Screen without Title): 800 x 480 - 1.5.

I have a Button; Height = 50 (dips in the Designer)

a) What should be its (new, scaled) height in a device (tablet) with: 1280 x 800 - 1 ?
I think: if the Variant scale was 1, as the tablet, the Height should be: (800 / 480) x 50 = 83.
Considering the different density: (1 / 1.5) x 83 = 55.
Well, it is scaled to... 49!


Given that the result was not convincing, I have set the layout to 800 x 480 - 1, then I have changed only the Scale of the Variant.

b) What should be the scaled height now?
Height should be: (800 / 480) x 50 = 83.
It is scaled to... 62!



Finally, both 100%y and GetDeviceLayoutValues.Height returns 752, despite the full screen and no title, instead of 800.



So... Happy New Year


 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
You left out the final question!!!!!
BTW, its exactly because of this that i prever creating my UI in code
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I highly recommend you to avoid using variants with scale other than 1.0. They will only make things more complicated.

AutoScaleAll works correctly. Many developers think that it will magically scale the layout to all devices. It doesn't.

It only slightly increases or decreases the views sizes based on the ratio between the variant size and the actual screen size.

As mentioned in the tutorials the scale rate should be around 0.3. If you are setting it to 1.0 then you are not using this feature correctly.

You need to use Anchors + designer script + autoscale to implement a good layout.

In almost all cases a stretched layout (like the one you create with code) is a bad layout.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Sorry, I don't understand and I don't agree.

You need to use Anchors
So, before anchors could I not get a well scaled layout?

I highly recommend you to avoid using variants with scale other than 1.0
Why give us the possibility to create a variant with scale different to 1.0?

should be around 0.3
In geometry I never heard the term "around"

Finally, both 100%y and GetDeviceLayoutValues.Height returns 752, despite the full screen and no title, instead of 800.

The designer will always remain for me a mistery.

Maybe I would need to know how it works internally.


Thanks anyway for the answer (exactly what I thought I got, unfortunately).



P.S. In the example, I had only need to get the height of a simple button double in the case where the device had double height compared to variant height (same densities).
The Designer should do this very easily.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So, before anchors could I not get a well scaled layout?
The solution before anchors was to implement the same feature with the designer script.

Why give us the possibility to create a variant with scale different to 1.0?
It works properly with any scale. There is no advantage for using non-normalized scales and it makes it more difficult to understand. The possibility is still there mainly for historic reasons.

In geometry I never heard the term "around"
Ok.

Finally, both 100%y and GetDeviceLayoutValues.Height returns 752, despite the full screen and no title, instead of 800.
This is not really related to the designer. These values return from the device APIs. Which device are you using?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This is not really related to the designer. These values return from the device APIs. Which device are you using?

This is really strange:

Now I have tried using an emulator. Always 752.
So, I opened the Designer and both the Layouts have
Show Title = True
Full Screen = False

but I am absolutely certain that I have set them exactly the opposite.

The only difference is that now I have not used the rapid debugger; but I think this may not have changed the file .bal.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Tested on b4a 5.20 beta

Main - fullscreen - includetitle - layout: "same" - 752

Act2 - fullscreen - includetitle - layout: "same" - 752
Act2 - fullscreen - includetitle - layout: "inverted" - 752


[p.s. Act2 - NOT fullscreen - NOT includetitle - layout: "same" - 699]

Those settings in the Designer have not influence.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
ButtonHeightAutoScaleAll





VARIANT
Device: 1280 x 800, scale = 1 (160 dpi)

Title-Full Screen:


Button1 Height:


AutoScaleRate:



Device: 1280 x 800, scale = 1 (160 dpi)
Screenshot
(part):


So, I set AutoScaleRate to 1; "Value of 1 is similar to specifying all values with percentage".
Button1.Height should be = 800(device h) / 480(variant h) * 50 = 83.333
(but, wow, it is almost right, 81 )
Perhaps the problem is that "similar".
 

Attachments

  • ButtonHeightAutoScaleAll.zip
    7.8 KB · Views: 187
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
If you go the "The screen does not have half pixels" way, you must then do some rounding...

800/480 = 1.66666667 which should be rounded to 1.67 BUT the designer works with only one decimal place for the density so we get 1.6
1.6 x 50 = 80 ... closer now, hugh!?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User

Yes, closer; but I suppose that Android can do same rounding and instead the result is 81.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…