An introduction to how to best integrate and optimize
graphical elements within your Android apps:
Two primary graphics related packages: the android.graphics.drawable
package and the android.view.animation package. These are collections of useful
classes for maximizing bitmap imagery and for working with images that support
the fourth dimension (time) via motion, commonly called animation.
Introducing the Drawables
The central set of classes used to control the graphics-related
content within your Android application is called the drawable package. This
package handles classes and methods related to drawing the following types of
visual assets onto the Android display screen:
Bitmaps: In a bitmap, a collection of pixels make up an
image—it’s a map of image bits, if you will. This is the most commonly used
drawable asset.
Shapes: Shapes are line drawings. They also are known as vectors,
like the lines architects use in CAD drawings. Common vector formats are EPS,
AI, or SVG.
Gradients: Gradients are smooth transitions from one color
to another color.They can be shaped in a straight line or occupy a circular
area.
Transitions: Shape transitions are smooth vector changes
between one shape and another shape. This process is sometimes referred to as morphing
or tweening.
Animation: Animation involves an image, shape, or object that
moves in some way.
Image transitions: These are smooth cross-fades between one
image andanother image. They are usually used to smoothly transition from one
image to another image.
In Android development, graphics-related items such as
gradients, image transitions, animated transformations, and frame-based
animation can all be termed drawables. With the exceptions of transformational
(tween or procedural) animation, all of these center their resource assets in
the /res/drawable folder.
The /res/drawable folder is also where you should put XML
files that define things like frame-based image animations and cross fading
image transitions.
Implementing Images :
Android is set up to automatically implement your images via
the project folder Hierarchy. But once you get used to it, you’ll find that it
is actually amazingly simple to use graphic resources, as extensive asset
reference coding is all but eliminated.
Core Drawable Subclasses :
Android offers more than a dozen types of customized
drawable objects. Look at the following core subclasses of android.graphics.drawable:
BitmapDrawable object:
Used to create, tile, stretch, and align bitmaps.
ColorDrawable object:
Used to fill certain other objects with color.
GradientDrawable
object: Used to create and draw custom gradients.
AnimationDrawable
object: Used to create frame-based animations.
TransitionDrawable
object: Used to create crossfade transitions.
LayerDrawable object:
Used to create composited PNG32 bitmaps or WebP bitmaps via multiple image
layers.
Bitmap Images :
Remember that a 32-bit PNG is a portable network graphic
format with 8-bits of red, green, blue, and alpha (ARGB or RGBA) and that 4 × 8
= 32, thus: PNG32. Besides the WebP format that is supported in Android 4.0 and
later, Android supports three mainstream bitmap image file formats: PNG, JPEG,
and GIF.
PNG Images :
The most powerful file format that Android supports, and the
one that it recommends using over all others, is the portable network graphics,
or PNG (pronounced “ping”) format. There are two primary types of PNG:
Indexed-color PNG8,
which uses a limited 256-color (8-bits of color allows 256 color values) image
palette, which is an index of up to 256 colors that an image uses to make up
its pixel colors
Truecolor PNG32, which uses a 32-bit color image that
includes a full 8-bit alpha channel (used for image compositing) and 8-bits
each of red, green, and blue image channels, or PNG24 for a truecolor PNG image
with no alpha channel included.
PNG is known as a lossless image file format because it loses
zero image data during the compression processing. This means that the image
quality is always 100% maintained. If designers know what they are doing, they
can get very high-quality graphics into a reasonably small data footprint by
using either the indexed-color PNG8 or the truecolor PNG32 or PNG24 image file formats,
depending upon how many colors are using in that image.
JPEG and GIF Images :
The next most desirable format to use is the JPEG image file
type. This type does not have an alpha channel. It uses lossy compression,
which means that it throws away some data to get a much better compression
result, but at the expense of your image quality. JPEG stands for joint photographic
experts group.
If you look closely at (zoom into, using GIMP) JPEG images,
you will see a lot of artifacts, such as areas of strange color variations or
what looks like dirt on the image (dirt that was not on the camera lens). JPEG
is useful for much higher-resolution (print resolution) images, where artifacts
are too small to be seen. So, it is not really as suitable for lower-resolution
smartphone screens.
JPEG is supported, but is not recommended for Android apps
because Google wants their product to look as pristine as possible, and PNG or
WebP formats are the sure-fire way to accomplish this.
No comments:
Post a Comment