Android categorises devices using two property. screen size and screen density.
There are four general sizes: small, medium, large, extra large.
there are four general screen densities: low(ldli), medium(mdpi), high (hdpi), extra high (xhdpi)
Application can provide different layout files so that the resources are taken accordingly. the naming is such that layout-
for example, a extra large screen would have the layout directory name as res/layout-xlarge
Android automatically scales the layout in order to fit the screen. Due to this layout for different screen sizes doesn't need to worry about the
absolute size of the UI elements but instead focus on the layout structure that affects the user experience.
A project that includes a default layout and an alternate layout for extra large screen will have resource folder something like below
res/layout/main.xml
res/layout-large/main.xml
If want to provide a different layout xml for landscape as well, below is the format
res/layout/main.xml
res/layout-land/main.xml
res/layout-large/main.xml
res/layout-large-land/main.xml
When creating the bit map resources, we need to keep in mind the density of the pixels on screen
xhdpi is 2.0 dpi , hdpi is 1.5dpi, mdpi is 1.0 dpi, ldpi is 0.75 dpi.
This means that a image needs to be 200x200 for xhdpi, 150x150 for hdpi, 100x100 for mdpi and 75x75 for ldpi.
Once the image is made like above, one needs to place these under the folder in the following structure
res/drwable-xhdpi/myimage.png
res/drawable-hdpi/myimage.png
res/drawable-mdpi/myimage.png
res/drawable-ldpi/myimage.png
System selects the bitmap according to the running device density.
as a note ldpi image resources are not necessary. If provided hdpi images, the system scales it down by 1/2 to fit the ldpi screens.
No comments:
Post a Comment