Android应用资源与图像处理1
Android应用资源与图像处理:
数组资源:res\values\arrays.xml
根元素:<rescources>
子元素:<array.../>普通数组,<String-array../>字符串数组,<integer-array../>整数数组.
子列表项:<item../>
访问:XML:<ListView android:entries="@array/books"/>
图片资源:/res/drawable/
StatelistDrawable:通过<item>组织多个Drawable对象
根元素:<selector>
子元素:<item> android:state_pressed, android:state_selected, android:state_checked, android:state_focused。
LayerDrawable:组织多个Drawable对象,根据顺序绘制
根元素:<layer-list>, <item>
ShapeDrawable:定义一个几何图形
根元素:<shape>
子元素:<corners>四个角弧度, <gradient>渐变色填充, <padding>内边距.
ClipDrawable:代表从图上截取一个图片段.
根元素:<clip>, 可用setLevel()来设置截取区域的大小.
AnimationDrawable:动画资源
根元素:<set>
子元素:<alpha>, <scale>, <translate>, <rotate>.
布局资源:/res/
Menu菜单资源:/res/menu/
根元素:<menu>
子元素:<item>----<group>
Style样式资源:/res/values/
根元素:<resources>
子元素:<style name="style2" parent="@style/style1">...
子项:<item../>
调用:<TextView style="@style/my_style">
Theme主题资源:/res/values/
类似于样式资源style,但定义时子项的name属性要加上"android:..."
Java调用:setTheme(android.R.style.myTheme).
AndroidManifest.xml中调用:<activity android:theme="@android:style/Theme.Dialog">
<application android:theme="@style/myTheme">
属性资源:/res/values/
根元素:<rescources>
子元素:<attr>,<declare-styleable>
原始资源:/res/raw, 或/assets/
AssetManager原始资源管理器.
Android图像处理:
1.BitmapFactory:
Bitmap代表一张位图,BitmapDrawable里封装一个Bitmap对象.
如:Bitmap bitmap = drawable.getBitmap(); BitmapDrawable drawable = new BitmapDrawable(bitmap);
创建Bitmap对象的方法:createBitmap(); createScaledBitmap();
BitmapFactory工具类:从不同的数据源解析创建出Bitmap对象.其包含方法:....
回收Bitmap对象:isRecycled(); recycle();
2.Android绘图:
继承了View组件,重写它的onDraw(Canvas canvas)方法.
显示View:在布局文件中创建<packagename.MyView>
Android绘图基础:Canvas画布,其包含方法:......
Android绘图基础:Paint画笔,其包含方法:......
Android绘图基础:Path路径,其包含方法:........
利用双缓冲技术实现画图板,游戏画面等.
Path绘制效果的实现:PathEffect.
3.图形特效处理
控制变换Matrix工具类:setTranslate()平移, Skew()倾斜, Rotate()旋转, Scale()缩放.
扭曲图像:drawBitmapMesh()方法.
填充图形:shader抽象类
填充实现类:BitmapShader位图平铺,LinearGradient线性渐变,RadialGradient图形渐变,SweepGradient角度渐变,ComposeShader组合渲染效果填充
4.逐帧动画Frame
XML资源文件定义:根元素<animation-list>,子元素<item>
android:onshot="false"循环播放, android:drawable-duration
可在main.xml中用<ImageView>将AnimationDrawable显示.
AnimationDrawable调用方法:start(),stop()
5.补间动画Tween
补间动画只定义开始帧和结束帧,中间帧由系统自动计算补齐.
借助Interpolator控制动画变化速度.
6.Surface View
自定义View绘图性能不好,Android提供了SuifaceView来代替View.