Android UI development topic (I) Interface Design
Recently, many users have expressed great interest in the design of the Android user interface. It is essential for the Android UI to develop self-painted controls and make games to have a good grasp of the drawing base. This topic will be discussed in 10 sections, and the possibility of OpenGL ES will be discussed later. This article mainly involves the following four packages:
Android. content. res Resource class
Android. graphics underlying graphics class
Android. view display class
Android. widget controls
1. android. content. res. Resources
For the Android platform's resource class android. content. res. resources may be unfamiliar to many netizens. Let's take a look at how the SDK introduces them. Contains classes for accessing application resources, such as raw asset files, colors, drawables, media or other files in the package, plus important device configuration details (orientation, input types, etc .) that affect how the application may behave. resources related to the Binary source file raw, Color colors, graphic drawables, and multimedia file media are managed through this class.
Int getColor (int id) corresponds to res/values/colors. xml
Drawable getDrawable (int id) corresponding to res/drawable/
XmlResourceParser getLayout (int id) corresponds to res/layout/
String getString (int id) and CharSequence getText (int id) correspond to res/values/strings. xml
InputStream openRawResource (int id) corresponds to res/raw/
Void parseBundleExtra (String tagName, AttributeSet attrs, Bundle outBundle) corresponds to res/xml/
String [] getStringArray (int id) res/values/arrays. xml
Float getDimension (int id) res/values/dimens. xml
2. android. graphics. Bitmap
As a Bitmap operation class, Bitmap provides many practical methods. The commonly used methods are summarized as follows:
Boolean compress (Bitmap. CompressFormat format, int quality, OutputStream stream) compresses a Bitmap object and saves it to an OutputStream based on its encoding and image quality. The first compression format is JPG and PNG.
Void copyPixelsFromBuffer (Buffer src) Copies bitmap pixels from a Buffer zone
Void copyPixelsToBuffer (Buffer dst) copies the current bitmap pixel content to a Buffer zone
We can see that the createBitmap object contains six methods in the current Android 2.1 SDK. Of course, they use API Level 1, so it is supported since Android 1.0 SDK, so you can rest assured to use it.
Static Bitmap createBitmap (Bitmap src)
Static Bitmap createBitmap (int [] colors, int width, int height, Bitmap. Config config)
Static Bitmap createBitmap (int [] colors, int offset, int stride, int width, int height, Bitmap. Config config)
Static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
Static Bitmap createBitmap (int width, int height, Bitmap. Config config)
Static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height)
Static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter) // create a scalable Bitmap object
Final int getHeight () to get the height
Final int getWidth () to get the width
Whether final boolean hasAlpha () has a transparent channel
Void setPixel (int x, int y, int color) sets the color of a certain Pixel
Int getPixel (int x, int y) gets the color of a certain pixel. android Development Network prompts that the int type returned here is the definition of color.
3. android. graphics. BitmapFactory
As an I/O class for Bitmap objects, the BitmapFactory class provides rich methods for constructing Bitmap objects, for example, to create a Bitmap object from a byte array, file system, resource ID, and input stream, all the members of this class, except decodeFileDescriptor, are frequently used in other overload methods.
Static Bitmap decodeByteArray (byte [] data, int offset, int length) // create a byte array
Static Bitmap decodeByteArray (byte [] data, int offset, int length, BitmapFactory. Options opts)
Static Bitmap decodeFile (String pathName, BitmapFactory. Options opts) // create a file from which the path must be fully written.
Static Bitmap decodeFile (String pathName)
Static Bitmap decodeFileDescriptor (FileDescriptor fd, Rect outPadding, BitmapFactory. Options opts) // create from input stream handle
Static Bitmap decodeFileDescriptor (FileDescriptor fd)
Static Bitmap decodeResource (Resources res, int id) // create from the APK file resource of Android. The error "android123" indicates that it is from drawable of/res /.
Static Bitmap decodeResource (Resources res, int id, BitmapFactory. Options opts)
Static Bitmap decodeResourceStream (Resources res, TypedValue value, InputStream is, Rect pad, BitmapFactory. Options opts)
Static Bitmap decodeStream (InputStream is) // create
Static Bitmap decodeStream (InputStream is, Rect outPadding, BitmapFactory. Options opts)
4. android. graphics. Canvas
We know that Java provides The Canvas class from the j2-midlet. Currently, on The Android platform, the main task is to manage The painting process. the Canvas class holds The "draw" CILS. to draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw CALS (writing into the bitmap), a drawing primitive (e.g. rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing ).