有关AndroidUI开发专题完整版.docx

上传人:b****6 文档编号:5661690 上传时间:2022-12-30 格式:DOCX 页数:18 大小:24.98KB
下载 相关 举报
有关AndroidUI开发专题完整版.docx_第1页
第1页 / 共18页
有关AndroidUI开发专题完整版.docx_第2页
第2页 / 共18页
有关AndroidUI开发专题完整版.docx_第3页
第3页 / 共18页
有关AndroidUI开发专题完整版.docx_第4页
第4页 / 共18页
有关AndroidUI开发专题完整版.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

有关AndroidUI开发专题完整版.docx

《有关AndroidUI开发专题完整版.docx》由会员分享,可在线阅读,更多相关《有关AndroidUI开发专题完整版.docx(18页珍藏版)》请在冰豆网上搜索。

有关AndroidUI开发专题完整版.docx

有关AndroidUI开发专题完整版

有关AndroidUI开发专题之界面设计

近期很多网友对Android用户界面的设计表示很感兴趣,对于AndroidUI开发自绘控件和游戏制作而言掌握好绘图基础是必不可少的。

本次专题分10节来讲述,有关OpenGLES相关的可能将放到以后再透露。

本次主要涉及以下四个包的相关内容:

  android.content.res资源类

  android.graphics底层图形类

  android.view显示类

  android.widget控件类

  一、android.content.res.Resources

  对于Android平台的资源类android.content.res.Resources可能很多网友比较陌生,一起来看看SDK上是怎么介绍的吧,Containsclassesforaccessingapplicationresources,suchasrawassetfiles,colors,drawables,mediaorotherotherfilesinthepackage,plusimportantdeviceconfigurationdetails(orientation,inputtypes,etc.)thataffecthowtheapplicationmaybehave.平时用到的二进制源文件raw、颜色colors、图形drawables和多媒体文件media的相关资源均通过该类来管理。

  intgetColor(intid)对应res/values/colors.xml

  DrawablegetDrawable(intid)对应res/drawable/

  XmlResourceParsergetLayout(intid)对应res/layout/

  StringgetString(intid)和CharSequencegetText(intid)对应res/values/strings.xml

  InputStreamopenRawResource(intid)对应res/raw/

  voidparseBundleExtra(StringtagName,AttributeSetattrs,BundleoutBundle)对应res/xml/

  String[]getStringArray(intid)res/values/arrays.xml

  floatgetDimension(intid)res/values/dimens.xml

  二、android.graphics.Bitmap

  作为位图操作类,Bitmap提供了很多实用的方法,常用的我们总结如下:

  booleancompress(Bitmap.CompressFormatformat,intquality,OutputStreamstream)压缩一个Bitmap对象根据相关的编码、画质保存到一个OutputStream中。

其中第一个压缩格式目前有JPG和PNG

  voidcopyPixelsFromBuffer(Buffersrc)从一个Buffer缓冲区复制位图像素

  voidcopyPixelsToBuffer(Bufferdst)将当前位图像素内容复制到一个Buffer缓冲区

  我们看到创建位图对象createBitmap包含了6种方法在目前的Android2.1SDK中,当然他们使用的是APILevel均为1,所以说从Android1.0SDK开始就支持了,所以大家可以放心使用。

  staticBitmapcreateBitmap(Bitmapsrc)

  staticBitmapcreateBitmap(int[]colors,intwidth,intheight,Bitmap.Configconfig)

  staticBitmapcreateBitmap(int[]colors,intoffset,intstride,intwidth,intheight,Bitmap.Configconfig)

  staticBitmapcreateBitmap(Bitmapsource,intx,inty,intwidth,intheight,Matrixm,booleanfilter)

  staticBitmapcreateBitmap(intwidth,intheight,Bitmap.Configconfig)

  staticBitmapcreateBitmap(Bitmapsource,intx,inty,intwidth,intheight)

  staticBitmapcreateScaledBitmap(Bitmapsrc,intdstWidth,intdstHeight,booleanfilter)//创建一个可以缩放的位图对象

  finalintgetHeight()获取高度

  finalintgetWidth()获取宽度

  finalbooleanhasAlpha()是否有透明通道

  voidsetPixel(intx,inty,intcolor)设置某像素的颜色

  intgetPixel(intx,inty)获取某像素的颜色,android开发网提示这里返回的int型是color的定义

  三、android.graphics.BitmapFactory

  作为Bitmap对象的I/O类,BitmapFactory类提供了丰富的构造Bitmap对象的方法,比如从一个字节数组、文件系统、资源ID、以及输入流中来创建一个Bitmap对象,下面本类的全部成员,除了decodeFileDescriptor外其他的重载方法都很常用。

  staticBitmapdecodeByteArray(byte[]data,intoffset,intlength)//从字节数组创建

  staticBitmapdecodeByteArray(byte[]data,intoffset,intlength,BitmapFactory.Optionsopts)

  staticBitmapdecodeFile(StringpathName,BitmapFactory.Optionsopts)//从文件创建,路径要写全

  staticBitmapdecodeFile(StringpathName)

  staticBitmapdecodeFileDescriptor(FileDescriptorfd,RectoutPadding,BitmapFactory.Optionsopts)//从输入流句柄创建

  staticBitmapdecodeFileDescriptor(FileDescriptorfd)

  staticBitmapdecodeResource(Resourcesres,intid)//从Android的APK文件资源中创建,android123提示是从/res/的drawable中

  staticBitmapdecodeResource(Resourcesres,intid,BitmapFactory.Optionsopts)

  staticBitmapdecodeResourceStream(Resourcesres,TypedValuevalue,InputStreamis,Rectpad,BitmapFactory.Optionsopts)

  staticBitmapdecodeStream(InputStreamis)//从一个输入流中创建

  staticBitmapdecodeStream(InputStreamis,RectoutPadding,BitmapFactory.Optionsopts)

  四、android.graphics.Canvas

  从J2MEMIDLET时我们就知道Java提供了Canvas类,而目前在Android平台中,它主要任务为管理绘制过程,TheCanvasclassholdsthe"draw"calls.Todrawsomething,youneed4basiccomponents:

ABitmaptoholdthepixels,aCanvastohostthedrawcalls(writingintothebitmap),adrawingprimitive(e.g.Rect,Path,text,Bitmap),andapaint(todescribethecolorsandstylesforthedrawing).

  该类主要提供了三种构造方法,分别为构造一个空的Canvas、从Bitmap中构造和从GL对象中创建,如下

  Canvas()

  Canvas(Bitmapbitmap)

  Canvas(GLgl)

  同时Canvas类的一些字段保存着重要的绘制方法定义,比如Canvas.HAS_ALPHA_LAYER_SAVE_FLAG保存时需要alpha层,对于Canvas类提供的方法很多,每个都很重要,下面我们一一作介绍

  booleanclipPath(Pathpath)

  booleanclipPath(Pathpath,Region.Opop)

  booleanclipRect(floatleft,floattop,floatright,floatbottom)

  booleanclipRect(Rectrect)

  booleanclipRect(floatleft,floattop,floatright,floatbottom,Region.Opop)

  booleanclipRect(Rectrect,Region.Opop)

  booleanclipRect(RectFrect)

  booleanclipRect(RectFrect,Region.Opop)

  booleanclipRect(intleft,inttop,intright,intbottom)

  booleanclipRegion(Regionregion,Region.Opop)

  booleanclipRegion(Regionregion)

  voidconcat(Matrixmatrix)

  voiddrawARGB(inta,intr,intg,intb)

  voiddrawArc(RectFoval,floatstartAngle,floatsweepAngle,booleanuseCenter,Paintpaint)

  voiddrawBitmap(Bitmapbitmap,Matrixmatrix,Paintpaint)

  voiddrawBitmap(int[]colors,intoffset,intstride,floatx,floaty,intwidth,intheight,booleanhasAlpha,Paintpaint)

  voiddrawBitmap(Bitmapbitmap,Rectsrc,Rectdst,Paintpaint)

  voiddrawBitmap(Bitmapbitmap,floatleft,floattop,Paintpaint)

  voiddrawBitmap(int[]colors,intoffset,intstride,intx,inty,intwidth,intheight,booleanhasAlpha,Paintpaint)

  voiddrawBitmap(Bitmapbitmap,Rectsrc,RectFdst,Paintpaint)

  voiddrawBitmapMesh(Bitmapbitmap,intmeshWidth,intmeshHeight,float[]verts,intvertOffset,int[]colors,intcolorOffset,Paintpaint)

  voiddrawCircle(floatcx,floatcy,floatradius,Paintpaint)

  voiddrawColor(intcolor)

  voiddrawColor(intcolor,PorterDuff.Modemode)

  voiddrawLine(floatstartX,floatstartY,floatstopX,floatstopY,Paintpaint)

  voiddrawLines(float[]pts,Paintpaint)

  voiddrawLines(float[]pts,intoffset,intcount,Paintpaint)

  voiddrawOval(RectFoval,Paintpaint)

  voiddrawPaint(Paintpaint)

  voiddrawPath(Pathpath,Paintpaint)

  voiddrawPicture(Picturepicture,RectFdst)

  voiddrawPicture(Picturepicture,Rectdst)

  voiddrawPicture(Picturepicture)

  voiddrawPoint(floatx,floaty,Paintpaint)

  voiddrawPoints(float[]pts,intoffset,intcount,Paintpaint)

  voiddrawPoints(float[]pts,Paintpaint)

  voiddrawPosText(char[]text,intindex,intcount,float[]pos,Paintpaint)

  voiddrawPosText(Stringtext,float[]pos,Paintpaint)

  voiddrawRGB(intr,intg,intb)

  voiddrawRect(RectFrect,Paintpaint)

  voiddrawRect(floatleft,floattop,floatright,floatbottom,Paintpaint)

  voiddrawRect(Rectr,Paintpaint)

  voiddrawRoundRect(RectFrect,floatrx,floatry,Paintpaint)

  voiddrawText(Stringtext,intstart,intend,floatx,floaty,Paintpaint)

  voiddrawText(char[]text,intindex,intcount,floatx,floaty,Paintpaint)

  voiddrawText(Stringtext,floatx,floaty,Paintpaint)

  voiddrawText(CharSequencetext,intstart,intend,floatx,floaty,Paintpaint)

  voiddrawTextOnPath(Stringtext,Pathpath,floathOffset,floatvOffset,Paintpaint)

  voiddrawTextOnPath(char[]text,intindex,intcount,Pathpath,floathOffset,floatvOffset,Paintpaint)

  voiddrawVertices(Canvas.VertexModemode,intvertexCount,float[]verts,intvertOffset,float[]texs,inttexOffset,int[]colors,intcolorOffset,short[]indices,intindexOffset,intindexCount,Paintpaint)

  staticvoidfreeGlCaches()

  booleangetClipBounds(Rectbounds)

  finalRectgetClipBounds()

  intgetDensity()

  DrawFiltergetDrawFilter()

  GLgetGL()

  intgetHeight()

  voidgetMatrix(Matrixctm)

  finalMatrixgetMatrix()

  intgetSaveCount()

  intgetWidth()

  booleanisOpaque()

  booleanquickReject(Pathpath,Canvas.EdgeTypetype)

  booleanquickReject(floatleft,floattop,floatright,floatbottom,Canvas.EdgeTypetype)

  booleanquickReject(RectFrect,Canvas.EdgeTypetype)

  voidrestore()

  voidrestoreToCount(intsaveCount)

  finalvoidrotate(floatdegrees,floatpx,floatpy)

  voidrotate(floatdegrees)

  intsave()

  intsave(intsaveFlags)

  intsaveLayer(floatleft,floattop,floatright,floatbottom,Paintpaint,intsaveFlags)

  intsaveLayer(RectFbounds,Paintpaint,intsaveFlags)

  intsaveLayerAlpha(floatleft,floattop,floatright,floatbottom,intalpha,intsaveFlags)

  intsaveLayerAlpha(RectFbounds,intalpha,intsaveFlags)

  finalvoidscale(floatsx,floatsy,floatpx,floatpy)

  voidscale(floatsx,floatsy)

  voidsetBitmap(Bitmapbitmap)

  voidsetDensity(intdensity)

  voidsetDrawFilter(DrawFilterfilter)

  voidsetMatrix(Matrixmatrix)

  voidsetViewport(intwidth,intheight)

  voidskew(floatsx,floatsy)

  voidtranslate(floatdx,floatdy)

  五、android.graphics.Color

  有关Android平台上表示颜色的方法有很多种,Color提供了常规主要颜色的定义比如Color.BLACK和Color.GREEN等等,我们平时创建时主要使用以下静态方法

  staticintargb(intalpha,intred,intgreen,intblue)构造一个包含透明对象的颜色

  staticintrgb(intred,intgreen,intblue)构造一个标准的颜色对象

  staticintparseColor(StringcolorString)解析一种颜色字符串的值,比如传入Color.BLACK

  本类返回的均为一个整形类似绿色为0xff00ff00,红色为0xffff0000。

我们将这个DWORD型看做AARRGGBB,AA代表Aphla透明色,后面的就不难理解,每个分成WORD整好为0-255。

AndroidUI开发专题

(二)之绘图基础

今天我们继续介绍Android平台底层绘图类的相关内容,在AndroidUI开发专题

(一)之界面设计中我们介绍了有关Android平台资源使用以及Bitmap相关类的操作,接下来将会以实例的方式给大家演示各种类的用处以及注意点。

今天我们继续了解android.graphics包中比较重要的绘图类。

  一、android.graphics.Matrix

  有关图形的变换、缩放等相关操作常用的方法有:

  voidreset()//重置一个matrix对象。

  voidset(Matrixsrc)//复制一个源矩阵,和本类的构造方法Matrix(Matrixsrc)一样

  booleanisIdentity()//返回这个矩阵是否定义(已经有意义)

  voidsetRotate(floatdegrees)//指定一个角度以0,0为坐标进行旋转

  voidsetRotate(floatdegrees,floatpx,floatpy)//指定一个角度以px,py为坐标进行旋转

  voidsetScale(floatsx,floatsy)//缩放

  voidsetScale(floatsx,floatsy,floatpx,floatpy)//以坐标px,py进行缩放

  voidsetTranslate(floatdx,floatdy)//平移

  voidsetSkew(floatkx,floatky,floatpx,floatpy)//以坐标px,py进行倾斜

  voidsetSkew(floatkx,floatky)//倾斜

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1