Android UI开发专题(一) 之界面设计
?该类主要提供了三种构造方法,分别为构造一个空的Canvas、从Bitmap中构造和从GL对象中创建,如下
Canvas()?
Canvas(Bitmap bitmap)?
Canvas(GL gl)
?同时Canvas类的一些字段保存着重要的绘制方法定义,比如Canvas.HAS_ALPHA_LAYER_SAVE_FLAG 保存时需要alpha层,对于Canvas类提供的方法很多,每个都很重要,下面我们一一作介绍
boolean? clipPath(Path path)
boolean? clipPath(Path path, Region.Op op)
boolean? clipRect(float left, float top, float right, float bottom)
boolean? clipRect(Rect rect)
boolean? clipRect(float left, float top, float right, float bottom, Region.Op op)
boolean? clipRect(Rect 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 matrix)
void? drawARGB(int a, int r, int g, int b)
void? drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
void? drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint)
void? drawBitmap(int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha, Paint paint)
void? drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
void? drawBitmap(Bitmap bitmap, float left, float top, Paint paint)
void? drawBitmap(int[] colors, int offset, int stride, int x, int y, int width, int height, boolean hasAlpha, Paint paint)
void? drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
void? drawBitmapMesh(Bitmap bitmap, int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset, Paint paint)
void? drawCircle(float cx, float cy, float radius, Paint paint)
void? drawColor(int color)
void? drawColor(int color, PorterDuff.Mode mode)
void? drawLine(float startX, float startY, float stopX, float stopY, Paint paint)
void? drawLines(float[] pts, Paint paint)?
void? drawLines(float[] pts, int offset, int count, Paint paint)
void? drawOval(RectF oval, Paint paint)
void? drawPaint(Paint paint)
void? drawPath(Path path, Paint paint)
void? drawPicture(Picture picture, RectF dst)
void? drawPicture(Picture picture, Rect dst)
void? drawPicture(Picture picture)
void? drawPoint(float x, float y, Paint paint)
void? drawPoints(float[] pts, int offset, int count, Paint paint)
void? drawPoints(float[] pts, Paint paint)
void? drawPosText(char[] text, int index, int count, float[] pos, Paint paint)
void? drawPosText(String text, float[] pos, Paint paint)
void? drawRGB(int r, int g, int b)
void? drawRect(RectF rect, Paint paint)
void? drawRect(float left, float top, float right, float bottom, Paint paint)
void? drawRect(Rect r, Paint paint)
void? drawRoundRect(RectF rect, float rx, float ry, Paint paint)
void? drawText(String text, int start, int end, float x, float y, Paint paint)
void? drawText(char[] text, int index, int count, float x, float y, Paint paint)
void? drawText(String text, float x, float y, Paint paint)
void? drawText(CharSequence text, int start, int end, float x, float y, Paint paint)
void? drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint)
void? drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint 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 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 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 paint, int saveFlags)
int? saveLayer(RectF bounds, Paint 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 matrix)
void? setViewport(int width, int height)
void? skew(float sx, float sy)
void? translate(float dx, float dy)
五、android.graphics.Color
?有关Android平台上表示颜色的方法有很多种,Color提供了常规主要颜色的定义比如Color.BLACK和Color.GREEN等等,我们平时创建时主要使用以下静态方法
static int argb(int alpha, int red, int green, int blue)? 构造一个包含透明对象的颜色
static int rgb(int red, int green, int blue)? 构造一个标准的颜色对象
static int parseColor(String colorString)? 解析一种颜色字符串的值,比如传入Color.BLACK
?本类返回的均为一个整形类似 ?绿色为0xff00ff00,红色为0xffff0000。我们将这个DWORD型看做AARRGGBB,AA代表Aphla透明色,后面的就不难理解,每个分成WORD整好为0-255。
?
From:http://hi.baidu.com/lfcaolibin/blog/item/ea08fce842338634b80e2d3c.html
?
?
