Android UI development topic (I) Interface Design

Source: Internet
Author: User
Tags drawtext transparent color
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)
Static bitmap createbitmap (INT [] colors, int offset, int stride, int width, int height, bitmap. 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)
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 ).
This class mainly provides three constructor Methods: constructing an empty canvas, constructing from bitmap, and creating from Gl object.
Canvas ()
Canvas (Bitmap bitmap)
Canvas (GL)
At the same time, some fields of the canvas class store important painting method definitions, such as canvas. the has_alpha_layer_save_flag requires the Alpha layer to be stored. There are many methods provided by the canvas class, each of which is very important. Next we will introduce them one by one.
Boolean clippath (Path)
Boolean clippath (Path, Region. Op OP)
Boolean cliprect (float left, float top, float right, float bottom)
Boolean cliprect (rect)
Boolean cliprect (float left, float top, float right, float bottom, Region. Op OP)
Boolean cliprect (rect, Region. Op OP)
Boolean cliprect (rectf rect)
Boolean cliprect (rectf rect, Region. Op OP)
Boolean cliprect (INT left, int top, int right, int bottom)
Boolean clipregion (Region region, Region. Op OP)
Boolean clipregion (region Region)
Void Concat (matrix)
Void drawargb (int A, int R, int g, int B)
Void drawarc (rectf oval, float startangle, float sweepangle, Boolean usecenter, paint)
Void drawbitmap (Bitmap bitmap, matrix, paint)
Void drawbitmap (INT [] colors, int offset, int stride, float X, float y, int width, int height, Boolean hasalpha, paint)
Void drawbitmap (Bitmap bitmap, rect SRC, rect DST, paint)
Void drawbitmap (Bitmap bitmap, float left, float top, paint)
Void drawbitmap (INT [] colors, int offset, int stride, int X, int y, int width, int height, Boolean hasalpha, paint)
Void drawbitmap (Bitmap bitmap, rect SRC, rectf DST, paint)
Void drawbitmapmesh (Bitmap bitmap, int meshwidth, int meshheight, float [] Verts, int vertoffset, int [] colors, int coloroffset, paint)
Void drawcircle (float CX, float cy, float radius, paint)
Void drawcolor (INT color)
Void drawcolor (INT color, porterduff. Mode)
Void drawline (float startx, float starty, float stopx, float stopy, paint)
Void drawlines (float [] pts, paint)
Void drawlines (float [] pts, int offset, int count, paint)
Void drawoval (rectf oval, paint)
Void drawpaint (paint)
Void drawpath (Path, paint)
Void drawpicture (picture, rectf DST)
Void drawpicture (picture, rect DST)
Void drawpicture (picture)
Void drawpoint (float X, float y, paint)
Void drawpoints (float [] pts, int offset, int count, paint)
Void drawpoints (float [] pts, paint)
Void drawpostext (char [] Text, int index, int count, float [] POs, paint)
Void drawpostext (string text, float [] POs, paint)
Void drawrgb (int r, int g, int B)
Void drawrect (rectf rect, paint)
Void drawrect (float left, float top, float right, float bottom, paint)
Void drawrect (rect R, paint)
Void drawroundrect (rectf rect, float RX, float ry, paint)
Void drawtext (string text, int start, int end, float X, float y, paint)
Void drawtext (char [] Text, int index, int count, float X, float y, paint)
Void drawtext (string text, float X, float y, paint)
Void drawtext (charsequence text, int start, int end, float X, float y, paint)
Void drawtextonpath (string text, Path, float hoffset, float voffset, paint)
Void drawtextonpath (char [] Text, int index, int count, Path, float hoffset, float voffset, paint)
Void drawvertices (canvas. vertexmode mode, int vertexcount, float [] Verts, int vertoffset, float [] texs, int texoffset, int [] colors, int coloroffset, short [] indices, int indexoffset, int indexcount, paint)
Static void freeglcaches ()
Boolean getclipbounds (rect bounds)
Final rect getclipbounds ()
Int getdensity ()
Drawfilter getdrawfilter ()
GL getgl ()
Int getheight ()
Void getmatrix (matrix CTM)
Final matrix getmatrix ()
Int getsavecount ()
Int getwidth ()
Boolean isopaque ()
Boolean quickreject (Path, canvas. edgetype type)
Boolean quickreject (float left, float top, float right, float bottom, canvas. edgetype type)
Boolean quickreject (rectf rect, canvas. edgetype type)
Void restore ()
Void restoretocount (INT savecount)
Final void rotate (float degrees, float PX, float Py)
Void rotate (float degrees)
Int save ()
Int save (INT saveflags)
Int savelayer (float left, float top, float right, float bottom, paint, int saveflags)
Int savelayer (rectf bounds, paint, int saveflags)
Int savelayeralpha (float left, float top, float right, float bottom, int Alpha, int saveflags)
Int savelayeralpha (rectf bounds, int Alpha, int saveflags)
Final void Scale (float Sx, float Sy, float PX, float Py)
Void Scale (float Sx, float SY)
Void setbitmap (Bitmap bitmap)
Void setdensity (INT density)
Void setdrawfilter (drawfilter filter)
Void setmatrix (matrix)
Void setviewport (INT width, int height)
Void skew (float Sx, float SY)
Void translate (float dx, float Dy)
5. Android. Graphics. Color
There are many ways to represent colors on the Android platform. Color provides general definition of major colors such as color. Black and color. Green. We usually use the following static methods when creating
Static int argb (INT Alpha, int red, int green, int blue) constructs a color that contains transparent objects
Static int RGB (INT red, int green, int blue) constructs a standard color object
Static int parsecolor (string colorstring) parses the value of a color string, for example
This class returns an integer similar to 0xff00ff00 in green and 0xffff0000 in red. We think of this DWORD type as the transparent color of aarrggbb. AA represents the transparent color of aphla, which is not hard to understand. Every word can be rounded to 0-255.

This article is transferred from www.35java.com

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.