Problem with sizes depending on screen quality

Hello, in my application I am using 2 extensions : ✨ Card View Extension for MIT App Inventor and FloatingActionButton - Color, Size, Radius, Position & Icons.. However, depending on my screen quality (which I can adjust from HD+ to WQHD+), the FAB size and paddings/margins do not seem the same even though the code is the same.

Here in WQHD+

And here in HD+

What can I do to fix this problem?
Thanks in advance,
Nico

set the size by screen width's percentage?

Yes, I defined the FAB size like this: size = screen1.width × 0.4

Your image looks not like 40%.

Exactly! The problem is here. When I set 40%, it doesn't show me 40%...

Please show your relevant blocks

Are those blocks in the Screen.Initialise event ? (It always helps to show all your relevant blocks !!)

If so, it could be that AI2 has not had enough time to set the width/height properties of the screen.

Use a clock timer with interval of 100ms (adjust as necessary), and place your extension blocks to create the floating button in the Clock timer.

I don't think that's the problem because this block is located at the very end of a UI initialization procedure, which is called in Screen1.Initialise.

Try it

Issue resolved using your extension @TIMAI2 :

To get a fixed value, regardless of screen density, simply multiply the desired size by the screen density like this :

//with "size", the desired size in pixel
size * density1.density

I tested this method on several phones and got the same result for all of them.

Thanks anyway to @Kevinkun and @TIMAI2 for their help!

1 Like