How to deal with Phones of different screen size?
deepak - Sun Feb 26 2012 23:19:51 GMT-0500 (EST)
Screen Size difference causes issues in Application
Screen Size difference causes issues in Application
deepak - Sun Feb 26 2012 23:26:58 GMT-0500 (EST)
Familiarize the Key Terms
Screen size
Actual physical size, measured as the screen's diagonal.
For simplicity, Android groups all actual screen
sizes into four generalized sizes:
small, normal, large, and extra large.
Screen density
The quantity of pixels within a physical area of the screen;
usually referred to as dpi (dots per inch).
For example, a "low" density screen has fewer pixels
within a given physical area, compared to a
"normal" or "high" density screen.
For simplicity,
Android groups all actual screen densities into
four generalized densities:
low, medium, high, and extra high.
Orientation
The orientation of the screen from the user's point of view.
This is either landscape or portrait,
meaning that the screen's aspect ratio is either
wide or tall, respectively. Be aware that not only do
different devices operate in different orientations
by default, but the orientation can change at
runtime when the user rotates the device.
Resolution
The total number of physical pixels on a screen.
When adding support for multiple screens,
applications do not work directly with resolution;
applications should be concerned only with
screen size and density, as specified by the
generalized size and density groups.
Density-independent pixel (dp)
A virtual pixel unit that you should use when defining
UI layout, to express layout dimensions or position
in a density-independent way.
deepak - Sun Feb 26 2012 23:29:07 GMT-0500 (EST)
Generalized Screen Sizes for Android
small
normal
large
xlarge
These are deprecated from API level 13
deepak - Sun Feb 26 2012 23:31:57 GMT-0500 (EST)
Screen Size and Resolution
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
deepak - Sun Feb 26 2012 23:35:06 GMT-0500 (EST)
Configuration Qualifiers
What are Configuration Qualifiers?
deepak - Sun Feb 26 2012 23:35:57 GMT-0500 (EST)
Answer is
A configuration qualifier is a string that you can append to a
resource directory in your Android project and
specifies the configuration for which the resources inside are designed
deepak - Sun Feb 26 2012 23:42:58 GMT-0500 (EST)
How to use Configuration Qualifiers?
- Create a new directory in your project's res/ directory and
name it using the format:
<resources_name>-<qualifier>
- <resources_name> is the standard resource name
(such as drawable or layout).
- <qualifier> is a configuration qualifier from table 1,
below, specifying the screen configuration for which these
resources are to be used (such as hdpi or xlarge).
You can use more than one <qualifier> at a time?
simply separate each qualifier with a dash.
- Save the appropriate configuration-specific resources
in this new directory. The resource files must be named
exactly the same as the default resource files.
deepak - Sun Feb 26 2012 23:48:50 GMT-0500 (EST)
Qualifiers types
Screen characteristic
Qualifier
Description
Size
small
Resources for small size screens.
normal
Resources for normal size screens.
(This is the baseline size.)
large
Resources for large size screens.
xlarge
Resources for extra large size screens.
Density
ldpi
Resources for low-density (ldpi)
screens (~120dpi).
mdpi
Resources for medium-density (mdpi)
screens (~160dpi).
(This is the baseline
density.)
hdpi
Resources for high-density (hdpi)
screens (~240dpi).
xhdpi
Resources for extra high-density (xhdpi)
screens (~320dpi).
nodpi
Resources for all densities. These are
density-independent resources.
The system does not
scale resources tagged with this qualifier,
regardless of the current screen's density.
tvdpi
Resources for screens somewhere between
mdpi and hdpi; approximately 213dpi. This is not
considered a "primary" density group. It is mostly
intended for televisions and most apps shouldn't
need it?providing mdpi and hdpi resources is
sufficient for most apps and the system will
scale them as appropriate. If you find it necessary
to provide tvdpi resources, you should size them
at a factor of 1.33*mdpi. For example,
a 100px x 100px image for mdpi screens
should be 133px x
133px for tvdpi.
Orientation
land
Resources for screens in the landscape
orientation (wide aspect ratio).
port
Resources for screens in the portrait
orientation (tall aspect ratio).
Aspect ratio
long
Resources for screens that have a
significantly taller or wider aspect ratio
(when in portrait
or landscape orientation, respectively) than
the baseline screen configuration.
notlong
Resources for use screens that have an
aspect ratio that is similar to the baseline screen
configuration.
deepak - Sun Feb 26 2012 23:51:57 GMT-0500 (EST)
How to handle layouts for Devices with different screen size?
1) As a practice try not to hard code any width/height
properties to an absolute value.
2) Create different layout folders for different sizes.
res/layout/my_layout.xml // normal screen size ("default")
res/layout-small/my_layout.xml // small screen size
res/layout-large/my_layout.xml // large screen size
res/layout-xlarge/my_layout.xml //extra large screen size
deepak - Sun Feb 26 2012 23:53:06 GMT-0500 (EST)
How to handle images with different Density?
1) Create different drawable folders for different densities.
res/drawable-mdpi/my_icon.png // medium density
res/drawable-hdpi/my_icon.png // high density
res/drawable-xhdpi/my_icon.png // extra high density
deepak - Sun Feb 26 2012 23:54:19 GMT-0500 (EST)
How to add the layout for Tablets?
Add the layouts to the layouts-xlarge folder.