- 浏览: 812762 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
wa19912002:
感谢 tomcat8改成7就好了
jstl的错误总结与解决方法 -
呵呵6666:
不错,谢谢分享!推荐个参考视频内容:http://www.ro ...
浅谈mysql主从复制的高可用解决方案 -
masuweng:
tabindex的微妙使用 -
syxfqw7:
完全正确,补充一下<beans:bean id=&quo ...
SpringSecurity3.1.2控制一个账户同时只能登录一次 -
fireinjava:
longToip直接用ipToLong反过来就好了 publi ...
IP地址与长整数之间的转换详解
摘自:http://blog.csdn.net/sayyanfu/archive/2011/02/18/6193809.aspx
Drawable 资源是对图像的一个抽象,你可以通过 getDrawable(int) 得到并绘制到屏幕上。这里有几种不同类型的 Drawable : Bitmap File 一个 Bitmap 图像文件( .png 、 .jpg 或 .gif )。 BitmapDrawable 。 Nine-Patch File 一个带有伸缩区域的 PNG 文件,可以基于 content 伸缩图片( .9.png )。 NinePatchDrawable 。 State List 一个 XML 文件,为不同的状态引用不同的 Bitmap 图像(例如,当按钮按下时使用不同的图片)。 StateListDrawable 。 Color 定义在 XML 中的资源,指定一个矩形(圆角可以有)的颜色。 PaintDrawable 。 Shape 一个 XML 文件,定义了一个几何形状,包括颜色和渐变。 ShapeDrawable 。 AnimationDrawable 资源的说明在【 Animation 资源】文章中。 Bitmap File 基本的 Bitmap 图像。 Android 支持几种不同格式的 Bitmap 文件: .png (最佳)、 .jpg (可接受)、 .gif (不要)。 注意: Bitmap 文件可能会被 aapt 工具进行无损图像压缩优化。例如,一个真彩色的 PNG (不超过 256 色)可能会被转换成一个带有颜色板的 8 位 PNG 。这样做能保证图片质量一样,但减少内存占用。因此,需要了解的是放在这个文件夹下的二进制图像在编译时可能会发生变更。如果你打算以位流方式读取图像来转化成 Bitmap 的话,可以把它们放到 res/raw 文件中,在这里,它们不会被优化。 File Location : res/drawable/filename.png (.png, .jpg, 或 .gif) 文件名会被当作资源 ID 使用。 Complied Resource Datatype : 指向 BitmapDrawable 的资源指针。 Resource Reference : R.drawable.filename ( Java ) @[package:]drawable/filename ( XML ) Example : 在 res/drawable/myimage.png 位置保存了一张图片,在 Layout XML 中可以应用这个图片到一个 View 上: <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/myimage" /> 下面的代码可以以 Drawable 方式得到图片: Resources res = getResources(); Drawable drawable = res.getDrawable(R.drawable.myimage); Nine-Patch File NinePatch 是一种 PNG 图像,可以定义拉伸区域,当 View 的 content 超出图像边界的话, Android 会拉伸它。典型用法是把这个图像设置为 View 的背景,而这个 View 至少有一个尺寸设置为“ wrap_content ”,当这个 View 变大来容纳 content 时, Nine-Patch 图像也会拉伸来匹配 View 的大小。 File Location : res/drawable/filename.9.png 文件名将被当作资源 ID 使用。 Complied Resource Datatype : 指向 NinePatchDrawable 的资源指针。 Resource Reference : R.drawable.filename ( Java ) @[package:]drawable/filename ( XML ) Example : 在 res/drawable/myninepatch.9.png 位置保存了一张图片,在 Layout XML 中可以应用这个图片到一个 View上: <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/myninepatch" /> State List StateListDrawable 是定义在 XML 中的 Drawable 对象,能根据状态来呈现不同的图像。例如, Button 存在多种不同的状态( pressed 、 focused 或 other ),使用 StateListDrawable ,你可以为 Button 的每个状态提供不同的按钮图像。 你可以在 XML 文件中描述状态列表。在 <selector> 元素里的每个 <item> 代表每个图像。每个 <item> 使用不同的特性来描述使用的时机。 当每次状态改变时, StateList 都会从上到下遍历一次,第一个匹配当前状态的 item 将被使用——选择的过程不是基于“最佳匹配”,只是符合 state 的最低标准的第一个 item 。 File Location Res/drawable/filename.xml 文件名将被当作资源 ID 使用。 Complied Resource Datatype : 指向 StateListDrawable 的资源指针。 Resource Reference : R.drawable.filename ( Java ) @[package:]drawable/filename ( XML ) Syntax : <? xml version = "1.0" encoding = "utf-8" ?> < selector xmlns:android = "http://schemas.android.com/apk/res/android" android:constantSize = ["true" | "false" ] android:dither = ["true" | "false" ] android:variablePadding = ["true" | "false" ] > < item android:drawable = "@[package:]drawable/drawable_resource " android:state_pressed = ["true" | "false" ] android:state_focused = ["true" | "false" ] android:state_selected = ["true" | "false" ] android:state_active = ["true" | "false" ] android:state_checkable = ["true" | "false" ] android:state_checked = ["true" | "false" ] android:state_enabled = ["true" | "false" ] android:state_window_focused = ["true" | "false" ] /> </selector> Elements : <selector> 必须。必须是根元素。可以包含一个或多个 <item> 元素。 Attributes : xmlns:android String 。必须。定义 XML 的命名空间,必须是 “ http://schemas.android.com/apk/res/android ”。 android:constantSize Boolean 。“ true ”表示随着状态变化, Drawable 的大小保持不变(所有状态中最大的 size);“ false ”表示大小会变化。默认是 false 。 android:dither Boolean 。“ true ”表示当 Bitmap 和屏幕的不是相同的像素设定时支持 Bitmap 抖动(例如, ARGB 8888 的 Bitmap 和 RGB 565 的屏幕);“ false ”表示不支持。默认是“ true ”。 android:variablePadding Boolean 。“ true ”表示 Drawable 的 Padding 可以变化;“ false ”表示 Padding 保持相同(所有状态的最大 Padding )。使能这一特征需要在状态变化时处理 Layout ,一般都不支持。默认值是 false 。 <item> 定义特定状态的 Drawable ,通过它的特性指定。必须是 <selector> 的子元素。 Attributes : android:drawable Drawable 资源。必须。指向一个 Drawable 资源。 android:state_pressed Boolean 。“ true ”表示按下状态使用(例如按钮按下);“ false ”表示非按下状态使用。 android:state_focused Boolean 。“ true ”表示聚焦状态使用(例如使用滚动球 /D-pad 聚焦 Button );“ false ”表示非聚焦状态使用。 android:state_selected Boolean 。“ true ”表示选中状态使用(例如 Tab 打开);“ false ”表示非选中状态使用。 android:state_checkable Boolean 。“ true ”表示可勾选状态时使用;“ false ”表示非可勾选状态使用。(只对能切换可勾选—非可勾选的构件有用。) android:state_checked Boolean 。“ true ”表示勾选状态使用;“ false ”表示非勾选状态使用。 android:state_enabled Boolean 。“ true ”表示可用状态使用(能接收触摸 / 点击事件);“ false ”表示不可用状态使用。 android:window_focused Boolean 。“ true ”表示应用程序窗口有焦点时使用(应用程序在前台);“ false ”表示无焦点时使用(例如 Notification 栏拉下或对话框显示)。 注意: 记住一点, StateList 中第一个匹配当前状态的 item 会被使用。因此,如果第一个 item 没有任何状态特性的话,那么它将每次都被使用,这也是为什么默认的值必须总是在最后(如下面的例子所示)。 Example : XML 文件保存在 res/drawable/button.xml 。 <? xml version = "1.0" encoding = "utf-8" ?> <selector xmlns:android = "http://schemas.android.com/apk/res/android" > <item android:state_pressed = "true" android:drawable = "@drawable/button_pressed" /> <!-- pressed --> <item android:state_focused = "true" android:drawable = "@drawable/button_focused" /> <!-- focused --> <item android:drawable = "@drawable/button_normal" /> <!-- default --> </selector> Layout XML 将这个 Drawable 应用到一个 View 上: <ImageView android:layout_height = "wrap_content" android:layout_width = "wrap_content" android:src = "@drawable/button" /> Color 定义在 XML 中的 color ,可以当作 Drawable 使用,来填充矩形区域(圆角可以有)。这种 Drawable 的行为很像是颜色填充。 注意: Color Drawable 是一种简单的资源,可以使用 name 特性来引用其值(不再是 XML 文件的名)。因此,你可以在一个 XML 文件中的 <resources> 元素下添加多个 Color Drawable 。 File Location : res/drawable/filename.xml 文件名随意。元素的 name 将会当作资源 ID 使用。 Complied Resource Datatype : 指向 PaintDrawable 资源的指针。 Resource Reference : R.drawable.color_name ( Java ) @[package:]drawable/color_name ( XML ) Syntax : <? xml version = "1.0" encoding = "utf-8" ?> < resources > < drawable name = "color_name " > color </drawable> </resources> Elements : <resources> 必须。必须是根节点。 没有特性。 <drawable> 一个 color Drawable 。其值可以是任何有效的十六进制颜色值或者 Color 资源。 Color 值总是以“ # ”开头,后面紧跟 Alpha-Red-Green-Blue 信息,格式是: #RGB 、 #ARGB 或者 #AARRGGBB 。 Attributes : name String 。必须。 Color 的名字。这个名字将被当作资源 ID 使用。 Example : XML 文件保存在 res/drawable/color.xml 。 <? xml version = "1.0" encoding = "utf-8" ?> <resources> <drawable name = "solid_red" > #f00 </drawable> <drawable name = "solid_blue" > #0000ff </drawable> </resources> Layout XML 将会把这个 Color Drawable 应用到一个 View 上: <TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:background = "@drawable/solid_blue" /> 代码中获取 Color Drawable 并应用到 View 上: Resources res = getResources () ; Drawable redDrawable = res . getDrawable ( R . drawable . solid_red ); TextView tv = ( TextView ) findViewByID ( R . id . text ); tv . setBackground ( redDrawable ); Shape 定义在 XML 中的几何形状。 File Location : res/drawable/filename.xml 文件名将被当作资源 ID 使用。 Complied Resource Datatype : 指向 ShapeDrawable 的资源指针。 Resource Reference : R.drawable.filename ( Java ) @[package:]drawable/filename ( XML ) Syntax : <? xml version = "1.0" encoding = "utf-8" ?> < shape xmlns:android = "http://schemas.android.com/apk/res/android" android:shape = ["rectangle" | "oval" | "line" | "ring" ] > < gradient android:angle = "integer " android:centerX = "integer " android:centerY = "integer " android:centerColor = "integer " android:endColor = "color " android:gradientRadius = "integer " android:startColor = "color " android:type = ["linear" | "radial" | "sweep" ] android:usesLevel = ["true" | "false" ] /> < solid android:color = "color " /> < stroke android:width = "integer " android:color = "color " android:dashWidth = "integer " android:dashGap = "integer " /> < padding android:left = "integer " android:top = "integer " android:right = "integer " android:bottom = "integer " /> < corners android:radius = "integer " android:topLeftRadius = "integer " android:topRightRadius = "integer " android:bottomLeftRadius = "integer " android:bottomRightRadius = "integer " /> </shape> Elements : <shape> 必须。必须是根元素。 Attributes : android:shape Keyword 。定义 Shape 的类型。有效的值包括: Value Desciption 矩形。默认形状。 椭圆。 水平直线。需要 <stroke> 元素定义线的宽度。 环形。 接下来的特性只能在 android:shape=”ring” 时使用: android:innerRadius Dimension 。内环的半径。 android:innerRadiusRatio Float 。以环的宽度比率来表示内环的半径。例如,如果 android:innerRadiusRatio=”5” ,内环半径等于环的宽度除以 5 。这个值可以被 android:innerRadius 覆盖。默认值是 9 。 android:thickness Dimension 。环的厚度。 android:thicknessRatio Float 。以环的宽度比率来表示环的厚度。例如,如果 android:thicknessRatio=”2” ,厚度就等于环的宽度除以 2 。这个值可以被 android:thickness 覆盖。默认值是 3 。 android:useLevel Boolean 。“ true ”表示可以当作 LevelListDrawable 使用。一般都为“ false ”。 <gradient> 为 Shape 指定渐变色。 Attributes : android:angle Integer 。渐变色的角度值。 0 表示从左到右, 90 表示从下到上。必须是 45 的倍数,默认是 0 。 android:centerX Float 。渐变色中心的 X 相对位置( 0-1.0 )。当 android:type=”linear” 时无效。 android:centerY Float 。渐变色中心的 Y 相对位置( 0-1.0 )。当 android:type=”linear” 时无效。 android:centerColor Color 。可选的颜色,出现在 start 和 end 颜色之间。 android:endColor Color 。 end 颜色。 android:gradientRadius Float 。渐变色的半径。当 android:type=”radial” 时有效。 android:startColor Color 。 start 颜色。 android:type Keyword 。渐变色的样式。有效值为: Value Description 线性渐变,默认值。 环形渐变。 start 颜色是处于中间的颜色。 sweep 渐变 android:useLevel Boolean 。“ true ”表示可以当作 LevelListDrawable 使用。 <solid> 填充 shape 的单一色。 Attributes : android:color Color 。这个颜色会应用到 shape 上。 <stroke> shape 的线形。 Attributes : android:width Dimension 。线的厚度。 android:color Color 。线的颜色。 android:dashGap Dimension 。间断线间的距离。仅在 android:dashWidth 设定时有效。 android:dashWidth Dimension 。间断线的大小。仅在 android:dashGap 设定时有效。 <padding> 内部 View 元素的边距。 Attributes : android:left Dimension 。左内边距。 android:top Dimension 。上内边距。 android:right Dimension 。右内边距。 android:bottom Dimension 。下内边距。 <corners> 为 shape 创建圆角。当 shape 是一个矩形时有效。 Attributes : android:radius Dimension 。圆角的半径。会被下面的特性覆盖。 android:topLeftRadius Dimension 。左上圆角半径。 android:topRightRadius Dimension 。右上圆角半径。 android:bottomLeftRadius Dimension 。左下圆角半径。 android:bottomRightRadius Dimension 。右下圆角半径。 Examples : XML 文件保存在 res/drawable/gradient_box.xml <? xml version = "1.0" encoding = "utf-8" ?> <shape xmlns:android = "http://schemas.android.com/apk/res/android" android:shape = "rectangle" > <gradient android:startColor = "#FFFF0000" android:endColor = "#80FF00FF" android:angle = "45" /> <padding android:left = "7dp" android:top = "7dp" android:right = "7dp" android:bottom = "7dp" /> <corners android:radius = "8dp" /> </shape> Layout XML 将被当作 ShapeDrawable 应用到一个 View 上: <TextView android:background = "@drawable/gradient_box" android:layout_height = "wrap_content" android:layout_width = "wrap_content" /> 代码中也可以获得 ShapeDrawable ,然后应用到 View 上: Resources res = getResources () ; Drawable shape = res . getDrawable ( R . drawable . gradient_box ); TextView tv = ( TextView ) findViewByID ( R . id . textview ); tv . setBackground ( shape );
"rectangle"
"oval"
"line"
"ring"
"linear"
"radial"
"sweep"
发表评论
-
Android软件的自动更新【升级改革版】
2012-12-19 15:44 140541、之前写过一篇说版本升级的,用到广播。感觉乱用,搞的有 ... -
gridview图片展示,长按进入编辑模式
2012-08-31 14:53 13949看到小米手机和其他一些图片显示软件,gridview显示 ... -
Android-ExifInterface如何正确存取Double类型坐标
2012-08-10 15:08 47751、向图片中存储一些属性,可以使用ExifInter ... -
Android软件的自动更新
2012-04-16 12:47 13936今天重新写了一篇 ... -
Android拍照,上传,预览综合【修改】
2011-12-07 14:21 32924最近需要做手机 ... -
百度地图的手动定位和自动定位
2011-07-07 18:45 52471最近由于项目需要,研究了下百度地图定位, ... -
谈Activity的生命周期
2011-07-01 13:42 1769摘自:http://blog.csdn.net/wyh0802 ... -
Android开发调试时logcat不显示问题
2011-07-01 13:40 2200摘自:http://dev.10086.cn/cmdn/wik ... -
AndroidManifest.xml详细介绍
2011-07-01 13:30 1796以下摘自网上,只为记录学习。 一、关于Andro ...
相关推荐
这是个android资源文件帮助文档,主要是res文件夹下的包括anim,drawable,xml等
Unity 调用Android文件资源管理器,可以选择Android手机上的图片,视频等一些列文件,并且获得相关的文件路径。直接导入Unity即可运行。测试已经通过
Android资源文件(学习android必备)Android资源文件(学习android必备)Android资源文件(学习android必备)
Android读取SMB服务器资源或者下载资源文件
通过输入一个apk文件和签名文件,输出相关的配置文件及资源文件被混淆的apk(带签名),注意是资源文件混淆不是代码混淆噢.
自己整理的Android12版本的系统资源目录分析,包括各个目录对应的分支 art: Android Runtime,一种App运行模式,区别于传统的Dalvik虚拟机,旨在提高Android系统的流畅性.PDF bionic:系统C库源代码,Android改造的C...
Android资源文件批量分类处理
Android文件管理器(增加了文件夹复制移动,下载资源暂停删除等,以及复制过程中的可视化进程)是一个基于Android开发的应用,包含常用文件操作以及文件下载功能,文件操作包括打开文件夹和打开各类的文件(apk、avi...
很全面的颜色相应代码资源文件,复制内容到colors.xml文件即可使用,方便使用
本文将反编译apk的java文件和资源文件重新关联引用对应,使得java文件能准确无误地重新引用资源文件。 (1)将反编译出的资源文件拷进studio中建项目,此时拷入的资源文件在R.java中会注册上; (2)从反编译出的...
该资源描述了Android Studio里边清理冗余的资源文件工具使用方法
设计Android应用程序的界面经常用到xml格式的布局文件。一个布局文件的作用是描述了: - 界面包含哪些控件(也叫组件或视图;示例有按钮,下拉框); - 控件之间的位置关系; - 如何显示界面的整体外观和各个...
使用android studio生成jar包,并且使用映射来完美调用资源文件。包含两个工程,一个如何生成jar包,一个是如何使用jar包,调用资源文件。使用详情可以关注我的blog,http://blog.csdn.net/jujishou521
Android文件资源管理器2.0的源码,包括程序有两个模块:文件管理部分和任务管理部分。
Android中使用xml文件定义颜色资源.pdf 学习资料 复习资料 教学资源
Android布局文件的属性值解析说明: 1 android:id [为控件指定相应的ID] 2 android:text [指定控件当中显示的文字 需要注意的是 这里尽量使用strings xml文件当中的字符串] 3 android:gravity [指定View组件的对齐...
Android资源文件详解.pdf
Android SO文件保护加固——混淆篇
android 文件存储