/cmdn/bbs/viewthread.php?tid=18736&page=1
#pid89255
Android UI 开发专题(一) 之界面设计
近期很多网友对Android 用户界面的设计表示很感兴趣,对于Android UI 开发自绘控件和游
戏制作而言掌握好绘图基础是必不可少的。本次专题分10 节来讲述,有关OpenGL ES 相关
的可能将放到以后再透露。本次主要涉及以下四个包的相关内容: android.content.res 资
源类
android.graphics 底层图形类
android.view 显示类
android.widget 控件类
一、android.content.res.Resources
对于Android 平台的资源类android.content.res.Resources 可能很多网友比较陌生,一起
来看看SDK 上是怎么介绍的吧,Contains classes for accessing application resources, such as
raw asset files, colors, drawables, media or other other files in the package, plus important device
configuration details (orientation, input types, etc.) that affect how the application may behave.平
时用到的二进制源文件raw 、颜色colors、图形drawables 和多媒体文件media 的相关资源均
通过该类来管理。
int getColor(int id) 对应res/values/colors.xml
Drawable getDrawable(int id) 对应res/drawable/
XmlResourceParser getLayout(int id) 对应res/layout/
String getString(int id) 和CharSequence getText(int id) 对应res/values/strings.xml
InputStream openRawResource(int id) 对应res/raw/
void parseBundleExtra (String tagName, AttributeSet attrs, Bundle outBundle) 对应res/xml/
String[] getStringArray(int id) res/values/arrays.xml
float getDimension(int id) res/values/dimens.xml
二、android.graphics.Bitmap
作为位图操作类,Bitmap 提供了很多实用的方法,常用的我们总结如下:
boolean compress(Bitmap.CompressFormat format, int quality, OutputStream stream) 压缩
一个Bitmap 对象根据相关的编码、画质保存到一个OutputStream 中。其中第一个压缩格式
目前有JPG 和PNG
void copyPixelsFromBuffer(Buffer src) 从一个Buffer 缓冲区复制位图像素
void copyPixelsToBuffer(Buffer dst) 将当前位图像素内容复制到一个Buffer 缓冲区
我们看到创建位图对象createBitmap 包含了6 种方法在目前的Android 2.1 SDK 中,当
然他们使用的是API Level 均为1,所以说从Android 1.0 SDK 开始就支持了,所以大家可以
放心使用。
static Bitmap createBitmap(Bitmap src)
static Bitmap createBitmap(int[] colors, int width, int height, Bitmap.Config config)
static Bitmap createBitmap(int[] colors, int o