[转]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 ...
随机推荐
- 深入理解Spring系列之一:开篇
转载 https://mp.weixin.qq.com/s?__biz=MzI0NjUxNTY5Nw==&mid=2247483810&idx=1&sn=a2df14fdb63 ...
- [LeetCode] Intersection of Two Linked Lists 两链表是否相交
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- HDU 5936 朋友
题意为给出一棵n个节点的树,这棵树的每条边有一个权值,这个权值只可能是0或1. 在一局游戏开始时,会确定一个节点作为根. 当一方操作时,他们需要先选择一个不为根的点,满足该点到其父亲的边权为1; 然后 ...
- Deploy Openstack with RDO and Change VNC console to Spice
Deploy Openstack with RDO and Change VNC console to Spice host os: centOS 7 server config network an ...
- groovy的三个强劲属性(一)Gpath
我们先从GPath开始,一个GPath是groovy代码的一个强劲对象导航的结构,名称的选择与XPath相似,XPath是一个用来描述XML(和等价物)文档的标准,正如XPath,GP ...
- Python如何实现文本转语音
准备 我测试使用的Python版本为2.7.10,如果你的版本是Python3.5的话,这里就不太适合了. 使用Speech API 原理 我们的想法是借助微软的语音接口,所以我们肯定是要进行调用 相 ...
- Nginx1.8.1 编译扩展https
nginx无缝编译扩展https 本贴只限用于通过编译安装的nginx,如果用的是yum源安装请卸载后参见 http://www.cnblogs.com/rslai/p/7851220.html 安装 ...
- js获取系统时间
//------------------------------------获取系统日期时间 var oDate=new Date(); //alert(oDate.getFullYear());// ...
- POJ 2752 Seek the Name, Seek the Fame(KMP求公共前后缀)
题目链接:http://poj.org/problem?id=2752 题目大意:给你一串字符串s找到所有的公共前后缀,即既是前缀又是后缀的子串. 解题思路: 如图所示 假设字符串pi与jq为符合条件 ...
- 关于真多核和加多核&线程由哪几部分组成
网上查的资料小结,没有考证. 真多核是指一个cpu多个核心,即多个内核. 假多核是指多个cpu捆绑形成的分布式计算,ARM针对服务器市场推出的处理器为多个cpu的 真多核的应用奔腾和因特尔 双核芯cp ...