The density is very important. Device resolution is made of Height, width and density (or scale).
See this page for common values. Note that the resolution should be 120 (scale = 0.75), 160 (scale = 1.0) , 240 (scale = 1.5) or 320 (scale = 2.0). Not any other value.
My HTC Desire has 480×800 so to me that would be the only thing mattering - except you say density is important *sigh*
Density is simply a function of device size and resolution.
If you had a device that was 1"x1" and a resolution of 240x240, then its density would be 240 dpi (dots per inch), which is referred to as a density of 1.5 based on a "standard" density of 160 dpi.
If you created a layout on that device and then ran it on a device that was 1"x1" with a resolution of 160x160 (denisty of 1), then your 240x240 layout wouldn't fit on it (obviously) without some adjustment.
If you are writing an app just for your own use, then density doesn't matter (assuming you got the layout working on your device). What's written at the link that I posted is aimed at people developing apps for distribution to others, in which case you must make adjustments to have the app run on devices of all different sizes and resolution.
You could also have a look at the Beginner's Guide.
Chapters:
5 Screen sizes and resolutions
8.6 Layout Variants.
Best regards.
There are lots of explanations in the documentation we suggested you.
What exactly do you not understand ?
You don't calculate the density, it is a property of the device and is determined by the device manufacturer.
It sorts of corresponds to the dots per inch of the display. A font size that renders 12 pixels high on a density 1 device will render 18 pixels high on a density 1.5 device.
A layout will look the same on a 320 x 480 density 1 device as on a 480 x 720 density 1.5 device but the latter will look better because of the increased resolution.
The density is the number of pixels per inch.
You could have two different devices with the same resolution for example 640*960 pixels but with different physical sizes, a 3.5'' and a 7'' screen.
The device with the 3.5'' screen has a density of 320 pixels/inch
and the tablet with the 7'' screen has a density of 160 pixels/inch.
If you design one layout file for both you will get all views shown proportional to the physical screen size, a same button will have its physical width and hight double on the 7'' screen than on the 3.5'' screen.
In case above I would make two different layout files because the big physical difference. You can put much more views, with a same physical dimensions, on a 7'' tablet screen than on a 3.5'' screen with the higher density.
So one layout file with 640*960 density 320 for the 3.5'' screen
and a second one withe 640*960 density 160 for the 7'' screen.
Yes.So you took 12 and multiplied it by 1.5?
Yes, but the OS will do it for you. The only difference could be different width/height ratios as explained in chapter '5 Screen sizes and resolutions' in the Beginner's Guide.So you multiply the base density value with width and height to get new values for other densitys?
Yes. For two reasons:So if I would want to make a layout for 480×800 and for 1280x800 it would be better to make two different layout files?
Yes. For two reasons:
- the physical size difference
- the different width/height ratios
Is there a function to read the density when running on a given device?
Dim dens As Float
dens = Density
Yes.
Yes. For two reasons:
- the physical size difference
- the different width/height ratios