[转]android中drawable资源的解释及例子
原文链接: http://blog.csdn.net/wode_dream/article/details/38584693
文章中的内容参考Dev Guide中的Drawable Resources,英文好的朋友可以直接去读英文。总结这篇文章的目的是自己在使用drawable资源遇到一些问题跟大家分享下,同时整理下自己对drawable的理解。
<bitmap android:src="@drawable/android_red"
</item>
</item>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<item
</selector>
<item android:state_focused="true"
<item android:state_hovered="true"
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
- <?xml version="1.0" encoding="utf-8"?>
- android:drawable="@drawable/status_off"
- <item
- </level-list>
可以在程序中设置imageView.getDrawable().setImageLevel(0)或imageView.getDrawable().setImageLevel(1)来切换图片。
- <transition
xmlns:android="http://schemas.android.com/apk/res/android">
- <item
android:drawable="@drawable/on" />
- <item
android:drawable="@drawable/off" />
- </transition>
- 在XML中的引用:
- <ImageButton
- android:id="@+id/button"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:src="@drawable/transition" />
ImageButton button = (ImageButton) findViewById(R.id.button);
drawable.startTransition(500);
xmlns:android="http://schemas.android.com/apk/res/android"android:drawable="@drawable/photo2"android:insetTop="100dp"android:insetRight="100dp"android:insetBottom="200dp"android:insetLeft="100dp" />http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/inset_drawable">android:drawable="@drawable/test_img"android:layout_width="match_parent"
android:id="@+id/clipimage"
</LinearLayout>Dev Guide中在ImageView中设置的是android:background="@drawable/clip_drawable",但是我使用background的时,会在程序中报空指针的错误。最后,使用程序控制:ImageView imageView=(ImageView)findViewById(R.id.clipimage);ClipDrawable clipDrawable=(ClipDrawable)imageView.getDrawable();clipDrawable.setLevel(5000);android:drawable="@drawable/test_img"第二步:在xml中引用<ImageView第三步,在程序中设置levelImageView scaleImage=(ImageView)findViewById(R.id.scaleimage);ScaleDrawable scale=(ScaleDrawable)scaleImage.getDrawable();scale.setLevel(10000);android:shape="rectangle"><gradientandroid:angle="45"/><paddingandroid:bottom="7dp" /><cornersandroid:radius="8dp" /></shape>第二步:xml中引用<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="shape例子"android:background="@drawable/shape_drawable"/>
[转]android中drawable资源的解释及例子的更多相关文章
- Android之旅十六 android中各种资源的使用
android中各种资源的使用: 在android开发中,各种资源的合理使用应该在各自的xml中进行定义,以便反复使用; 字符串资源:strings.xml,xml中引用:@string/XXX,ja ...
- Android中的资源文件
最近复习Android资源文件的内容,留下点记录以备后用. Android中的资源主要是指存放在应用程序或者Framework相应包下/res中的内容.它们可以被本地化,如果必要的话会被编译成二进制文 ...
- Android中的动画具体解释系列【4】——Activity之间切换动画
前面介绍了Android中的逐帧动画和补间动画,并实现了简单的自己定义动画.这一篇我们来看看怎样将Android中的动画运用到实际开发中的一个场景--Activity之间跳转动画. 一.定义动画资源 ...
- Android中的资源访问
Android中的资源是指非代码部分,指外部文件. assets中保存的一般是原生的文件,例如MP3文件,Android程序不能直接访问,必须通过AssetManager类以二进制流的形式来读取. r ...
- 今天给大家分享一下Android中的资源与国际化的问题
摘要:该文章将向大家分享Android中的资源与国际化的问题. 今天给大家分享一下Android中的资源与国际化的问题,通常我们新建一个Android工程,目录结构如下图所示: 我们主要看一下layo ...
- Android中的资源与国际化!
Android中的资源与国际化的问题,通常我们新建一个Android工程,目录结构如下图所示: 我们主要看一下layout与values目录,layout里的xml文件的我们应用使用布局的文件,val ...
- Android中时间戳的详细解释
Android中时间戳的详细解释: (1).定义: 时间戳就是根据当前系统时间生成的一组随机数字. (2).作用: 作为对数据唯一性的一种判断依据.避免了重复修改数据所带来的错误! (3).应用: ( ...
- Android中Drawable分类汇总(上)
Android把可绘制的对象抽象为Drawable,不同的图形图像资源就代表着不同的drawable类型.Android FrameWork提供了一些具体的Drawable实现,通常在代码中都不会直接 ...
- android的drawable资源
1.android中可以通过xml文件配置资源,比如字符串啦,整数拉.浮点数等等,当然也可以配置图片资源和选择器,下面我们就看看几种图片资源的配置. @1矩形方框,带渐变色的配置代码 <?xml ...
随机推荐
- 阿里云一键web环境包
下载地址:https://files.cnblogs.com/files/wordblog/af3a48ef-3a13-479e-85c9-ead61173126c.zip 先把安装包传到服务器上用w ...
- frameset测试
frame不能放在body标签内.指定name属性,为这一个框架指定名字,在html的a的target属性可以设为target="right"在该框架显示跳转的页面.(常用于后台管 ...
- 47、求1+2+3+...+n
一.题目 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 二.解法 public class Solut ...
- Java并发编程(二)
1.Lock接口 在Lock接口出现之前,Java程序是靠synchronized关键字实 ...
- mysql安装后开启远程
操作系统为centos7 64 1.修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 mysqld 启动时不对密码进行验证 2. ...
- 常用的Oracle的doc命令
常用的Oracle的doc命令 1.连接数据库 普通用户连接数据库: conn scott/tiger --(默认的用户名/密码).conn 即"connection"连接数据库的 ...
- cgi与html相互调用
html中调用cgi.<form action="/cgi-bin/mult.cgi" method="get" target="_blank& ...
- vmware linux虚拟机连接ip设置
首先: 点击VMware 编辑->虚拟网络编辑器: 然后选中VMnet8的查看NAT设置: 上图第二步(记下红框中网关地址和子网掩码): 第三步(用于设置虚拟机地址范围): 接下来就是设置虚拟机 ...
- 深入理解JS各种this指向问题
说到this,入前端坑的人都知道这是JS初期语言毕竟之路.很多人(我就是)对于this的了解很模糊,或者不够全面.最近打算在反过来在看下es6,在es6中又出现了箭头函数对于this的理解有多了层认识 ...
- vscode 解决vue emmet不起作用
现在 vscode 自带的提示已经很好用了,大部分时间自带的提示展示的 emmet 内容已经是所需的了 在首选项 设置中配置 v1.15.1 之后需要这样设置: "emmet.trigger ...