近期很多網友對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緩沖區
我們看
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)
新聞熱點
疑難解答