Session 4
 ...
 Actual physical size, measured as the screen's
diagonal.
 For simplicity, Android groups all actual screen sizes
into four generalized sizes:
 Small
 Normal
 Large
 Extra large
 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
 Extra high
 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.
 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.
 A virtual pixel unit that you should use when defining UI
layout, to express layout dimensions or position in a
density-independent way.
 The density-independent pixel is equivalent to one physical
pixel on a 160 dpi screen, which is the baseline density
assumed by the system for a "medium" density screen. At
runtime, the system transparently handles any scaling of
the dp units, as necessary, based on the actual density of
the screen in use. The conversion of dp units to screen
pixels is simple: px = dp * (dpi / 160). For example, on a 240
dpi screen, 1 dp equals 1.5 physical pixels. You should
always use dp units when defining your application's UI, to
ensure proper display of your UI on screens with different
densities.
 Explicitly declare in the manifest which screen sizes
your application supports
 Provide different layouts for different screen sizes
 Provide different bitmap drawables for different screen
densities
 The system uses the appropriate alternative resource
 If no matching resource is available, the system uses
the default resource and scales it up or down as needed
to match the current screen size and density
 android:id
 android:text
 android:width
 android:height
 android:padding
 fill_parent (MATCH_PARENT in API Level 8 and higher)
 Setting the layout of a widget to fill_parent will force it to
expand to take up as much space as is available within the
layout element it's been placed in. It's roughly equivalent of
setting the dockstyle of a Windows Form Control to Fill.
 Setting a top level layout or control to fill_parent will force it
to take up the whole screen.
 wrap_content
 Setting a View's size to wrap_content will force it to expand
only far enough to contain the values (or child controls) it
contains. For controls -- like text boxes (TextView) or images
(ImageView) -- this will wrap the text or image being shown.
For layout elements it will resize the layout to fit the controls
/ layouts added as its children.
 Use wrap_content, fill_parent, or the dp unit for layout
dimensions
 Do not use hard-coded pixel values in your application
code
 Do not use AbsoluteLayout
 Use size and density-specific resources
 Pixels - px
 Inches - in
 Millimeters - mm
 Points - pt
 Density-independent Pixels - dp
 Scale-independent Pixels - sp
 Pixels - corresponds to actual pixels on the screen.
 Inches - based on the physical size of the screen.
 Millimeters - based on the physical size of the screen.
 Points - 1/72 of an inch based on the physical size of
the screen.
 Density-independent Pixels - an abstract unit that is
based on the physical density of the screen. These
units are relative to a 160 dpi screen, so one dp is one
pixel on a 160 dpi screen. The ratio of dp-to-pixel will
change with the screen density, but not necessarily in
direct proportion. Note: The compiler accepts both
"dip" and "dp", though "dp" is more consistent with
"sp".
 Scale-independent Pixels - this is like the dp unit, but
it is also scaled by the user's font size preference. It is
recommend you use this unit when specifying font
sizes, so they will be adjusted for both the screen
density and user's preference.
 Check AndroidManifest.xml
 Check Permissions
 Check min-sdk
 Use try-catch
 Handling….
 Logcat
 Break points
 Toast
 Toast.makeText(getApplicationContext(), "this is my
Toast message!", Toast.LENGTH_LONG).show();
 AlertDialog
 http://www.androidhive.info/2011/09/how-to-show-
alert-dialog-in-android/
 Search for “Android Design Patterns”

Android Development - Session 4

  • 1.
  • 2.
  • 3.
     Actual physicalsize, measured as the screen's diagonal.  For simplicity, Android groups all actual screen sizes into four generalized sizes:  Small  Normal  Large  Extra large
  • 4.
     The quantityof 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  Extra high
  • 5.
     The orientationof 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.
  • 6.
     The totalnumber 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.
  • 7.
     A virtualpixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.  The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
  • 9.
     Explicitly declarein the manifest which screen sizes your application supports  Provide different layouts for different screen sizes  Provide different bitmap drawables for different screen densities
  • 10.
     The systemuses the appropriate alternative resource  If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density
  • 12.
     android:id  android:text android:width  android:height  android:padding
  • 13.
     fill_parent (MATCH_PARENTin API Level 8 and higher)  Setting the layout of a widget to fill_parent will force it to expand to take up as much space as is available within the layout element it's been placed in. It's roughly equivalent of setting the dockstyle of a Windows Form Control to Fill.  Setting a top level layout or control to fill_parent will force it to take up the whole screen.  wrap_content  Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.
  • 14.
     Use wrap_content,fill_parent, or the dp unit for layout dimensions  Do not use hard-coded pixel values in your application code  Do not use AbsoluteLayout  Use size and density-specific resources
  • 15.
     Pixels -px  Inches - in  Millimeters - mm  Points - pt  Density-independent Pixels - dp  Scale-independent Pixels - sp
  • 16.
     Pixels -corresponds to actual pixels on the screen.
  • 17.
     Inches -based on the physical size of the screen.
  • 18.
     Millimeters -based on the physical size of the screen.
  • 19.
     Points -1/72 of an inch based on the physical size of the screen.
  • 20.
     Density-independent Pixels- an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
  • 21.
     Scale-independent Pixels- this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
  • 22.
     Check AndroidManifest.xml Check Permissions  Check min-sdk  Use try-catch  Handling….
  • 23.
     Logcat  Breakpoints  Toast  Toast.makeText(getApplicationContext(), "this is my Toast message!", Toast.LENGTH_LONG).show();  AlertDialog  http://www.androidhive.info/2011/09/how-to-show- alert-dialog-in-android/
  • 24.
     Search for“Android Design Patterns”