How does scaling work?

canalrun

Well-Known Member
Licensed User
Longtime User
Hello All,
I am trying to determine exactly how scaling works and what kind of variants I should include for my application.

My phone is a Samsung Vibrant with 480x800 pixels, 240 dpi, scale 1.5.

I would like this application to work on other android phones.

I am currently trying to find a list of popular android phones and their screen pixel resolution, but have not had much luck.

Let's suppose someone downloads my app and their phone has a screen resolution of 400x600. What is going to happen?

Will B4A automatically scale the control sizes and positions for the smaller screen in proportion to the sizes and positions that I designed for my target screen size? That is: Will buttons be narrower and shorter and be positioned in the same relative screen location? Will the same be true for other controls?

Is they are an overview description of the scaling algorithm somewhere?

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
I did find a nice site that describes the most common android device screen resolutions at:

Designer?s Guide to Supporting Multiple Android Device Screens | ANidea ? powered by the minds at AgencyNet

Supporting 320x480 and 480x800 seems to cover the major two, although Motorola throws in that 480x854. I guess they want to keep us on our toes.

Hopefully I can try this on the emulator to see what happens.

I saw a question in the forums concerning one device that was 200x392 or some weird number of pixels. I'm curious what happens when an app encounters a device like that.

Barry.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The scaling algorithm is pretty simple. It changes the layout based on a single value which is the device dots per inch value. The base value is 160. This matches a scale of 1.0. High resolution devices scale is 1.5.

This means that the width of the following button:
B4X:
Button1.Width = 100dip
will be 100 pixels on a medium resolution device (like HTC Wildfire) and 150 pixels on a high resolution device.

The screen width and height are not considered at all.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

Kim Rowden

Member
Licensed User
Longtime User
Erel,
so if I'm trying to set a button size based on half the size of some other variable should I use :
B4X:
btnSearch.Width = DipToCurrent(some_variable / 2)
Clearly the following won't work because it results in a string and not an int:
B4X:
btnSearch.Width = (some_variable / 2) & "dip"
Thanks,
-Kim
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should set either:
B4X:
some_variable = 100dip
btnSearch.Width = some_variable / 2
or (I wouldn't use this)
B4X:
some_variable = 100
btnSearch.Width = DipToCurrent(some_variable / 2)
or
B4X:
btnSearch.Width = btnSave.Width / 2
Best regards.
 
Upvote 0
Top