Android Drawable,ColorMatrix

Android Drawable,ColorMatrix Drawable的子类有StateListDrawableNinePatchDrawable等。StateListDrawableStateListDrawable中包含一组状态Drawable对象对应的selector/标签中的item标签属性中组合了state和drawable或color?xml version1.0 encodingutf-8?selector xmlns:androidhttp://schemas.android.com/apk/res/androiditem android:state_enabledfalse android:drawabledrawable/icon2 //selectorStateListDrawable也可以设置给textColor。LayerDrawableLayerDrawable中包含一组分层Drawable对象对应使用layer-list/标签描述。其item标签中的android:bottom|top|left|right等属性用于指定一个长度值,用于指定将该Drawable对象绘制到目标组件的指定位置。ShapeDrawableShapeDrawable定义基本几何图形然后给图形定义一些外观效果。对应使用shape/标签android:shaperectangle|voal|line|ring属性指定几何类型矩形、椭圆、线、圆。标签内部用成员corners/定义角弧度padding/定义内边距size/定义尺寸和边颜色solid/定义单色填充gradient/定义填充渐变类型和颜色stroke/定义边框宽度和颜色。示例?xml version1.0 encodingUTF-8?shape xmlns:androidhttp://schemas.android.com/apk/res/android!--设置背景色为透明色--solid android:color#0000/!--设置红色边框--stroke android:width2dp android:color#f00 //shape?xml version1.0 encodingUTF-8?shape xmlns:androidhttp://schemas.android.com/apk/res/android android:shaperectangle!--指定圆角矩形的4个圆角的半径--corners android:topLeftRadius20dpandroid:topRightRadius10dpandroid:bottomRightRadius20dpandroid:bottomLeftRadius10dp/!--指定边框线条的宽度和颜色--stroke android:width4px android:color#f0f \!--指定使用渐变背景色,使用sweep类型的渐变颜色从红色→绿色→蓝色--gradientandroid:startColor#f00android:centerColor#0f0android:endColor#00fandroid:typesweep//shapeClipDrawableClipDrawable表示从位图上截取的图片片段对应标签clip/标签属性中android:drawable指定要截取的源drawableandroid:clipOrientation指定截取方向水平或垂直android:gravity指定截取对齐方式。ClipDrawable调用setLevel设置截取尺寸大小值从0到整张10000。使用ClipDrawable加定时器可实现图片徐徐展开效果进而可以应用到进度条。AnimationDrawable资源多张图片逐个播放称为帧动画一张图片平移变换等称为补间(Tween)动画。定义补间动画资源用set/标签属性android:duration设置持续时间属性android:interpolater设置动画变化速度匀速、加速、减速、变速等属性android:shareInterpolater设置是否统一速度属性android:filllAfter设置是否保留变换结果。内部用alpha/设置透明度变化scale/设置缩放变化translate/设置位移变化rotate/设置旋转变化。定义补间动画的思路很简单:设置一张图片的开始状态(包括透明度、位置、缩放比、旋转度),并设置该图片的结束状态(包括透明度、位置、缩放比、旋转度),再设置动画的持续时间,Android系统会使用动画效果把这张图片从开始状态变换到结束状态。当进行缩放变换(scale)、旋转(rotate)变变换时,还需要指定pivotX、pivotY两个属性,这两个属性用于指定变换的中心点--比如进行旋转变换时,需要指定旋轴点;进行缩放变换时,需要指定中心点。先用AnimationUtils.loadAnimation()得到Animation对象再把它设置为imageView的startAnimation方法的参数由视图来启动动画。PropertyAnimation属性动画资源Animator是一个抽象类代表一个属性动画,通常会使用它的子类:AnimatorSet、ValueAnimator、ObjectAnimator、TimeAnimator。定义属性动画的XML资源文件能以如下三个元素中的任意一个作为根元素。set.../:用于包含objectAnimator.../、animator.../或set.../子元素,该元素定义的资源代表AnimatorSet对象。objectAnimator.../:用于定义ObjectAnimator动画。animator.../:用于定义ValueAnimator动画。把应用此动画的视图设置为此属性动画的target参数由动画对象自己启动动画。1. 9.png格式的图片是安卓平台在png图片的基础上新创的格式。它是由9个补丁patch)组成的png命名为 .9.png与传统的png格式图片相比 9.png 格式图片在图片四周有一圈一个像素点组成的边沿该边沿用于对图片的可扩展区和内容显示区进行定义。android会自动将.9.png的文件当做 9 patch文件来处理9.png的文件就是一个png文件其特殊之处在于周围一圈的框框由 0x00000000或者 0xffffffff 组成即有一圈黑白框黑框所框住的地方是会被resize的另外的4个角不会被resize, 而上下左右的四块会被单向resize。这对于一些按钮的png十分有好处可以保持四周的圆角尺寸不变而中心放大。9.png图片的四周与普通的png图片相比多了一个像素位的白色区域该区域只有在图片被还原和制造的时候才能看到当打包后无法看见并且图片的总像素会缩小2个像素比如23x23像素的9.png图片被打包后会变成21x21像素。典型的例子是四个角是弧形的按钮图片被拉伸时要保持弧形角不被拉伸可设置四个圆角内侧的4条线拉伸这样会保持中间内部的图像形状不变化相对位置也不偏移。这样图片被分成了9个部分所以叫nine patch。指定颜色值变化范围比较小的区域为伸缩区域来防止图片伸缩变形。内容区域一般设置为小于等于伸缩区域。如果res/drawable目录中的9.png中没有黑线eclipse会报错。2.android\tools目录中有一个draw9patch.bat即画黑边工具draw9patch.bat的使用方法是打开一个普通的png图然后将四周的中心用鼠标点上。再保存。在右边可以看到缩放后的效果。{注意对于从别人apk中破解9.png的时候android编译器已经将9.png的边框去掉了所以还要再使用draw9patch.bat自己整一下。}选中show patches左侧黑色边线对应的绿色区域是上下拉伸的区域上侧黑色边线对应的绿色区域是左右拉伸的区域。被拉伸的区域贯穿上下或左右不能实现只拉伸内部一块区域。右键或shift左键清除黑线。从apk文件中解压得到的.9.png是已经去掉了黑边了的。在打包成apk时.9.png中的空白像素被去掉了。可能这些信息被记录到了包的另外的地方。draw9patch右侧的显示表示上下拉伸左右拉伸上下左右同时拉伸时的效果同时还可以看到内容区域默认是整个图片。但是实际情况可能是当不设置内容区域时NinePatch图片使用的就是拉伸区域作为内容区域而不是NinePatch编辑器中指示的图片全部区域。3.GradientDrawable 梯度绘图渐变绘图可以把它设置给窗口等对象的背景实现渐变效果。4.A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the Viewin which you have placed it as the background.NinePatchDrawable 的特性是在它作为background时展现的。If a View object sets the NinePatch as its background and then specifies the Views text, it will stretch itself so that all the text fits inside onlythe area designated by the right and bottom lines (if included).同时它的内容区域是为视图的文本内容准备的。Tools Draw 9-patch中查找更多介绍。http://developer.android.com/guide/developing/tools/draw9patch.html1.使用InputStream inputStream context.getResources().openRawResource(resId);读取在res\raw中的a.html时报WARN/ResourceType(406): getEntry failing because entryIndex 2 is beyond type entryCount 2修改为a.data后读取成功。2.3.android不建议使用内部的图片资源想使用最好拷贝一份使用。Warning: Because these resources can change between platform versions, you should not reference these icons using the Android platform resource IDs(i.e. menu icons underandroid.R.drawable).If you want to use any icons or other internal drawable resources, you should store a local copy of those icons or drawables in your application resources,then reference the local copy from your application code. In that way, you can maintain control over the appearance of your icons,even if the systems copy changes. Note that the grid below is not intended to be complete.在D:\android-sdk_r10-windows\platforms\android-8\data\res中可以找到。http://www.rexsee.comhttp://www.itbinary.com/art/14/167.htmlhttp://www.apkbus.com/forum.php?modviewthreadtid2276extrapage%3D14.Android图片处理Matrix,ColorMatrixhttp://www.cnblogs.com/leon19870907/articles/1978065.html