[转]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 ...
随机推荐
- django框架<二>
django框架: Models 1.基本创建 Django提供了一个抽象层("Model")的构建和管理Web应用程序的数据. Django使用一种新的方式,即:关系对象映射 ...
- Opencv 配置VS2012
开始接触图像处理有一段时间了,经过前期的调研,和相关入门知识的学习,开始接触一些图像处理应用的工具.Opencv是一个图像处理的开源库,由于其开放的协议架构,国内外很多科研机构和团队都在基于openc ...
- 76.ZYNQ-用PS控制DDR3内存读写
本编文章的目的主要用简明的方法对DDR3进行读写,当然这种方式每次读写都需要CPU干预,效率是比较低的,但是这是学习的过程吧. 本系列文章尽可能的让每一个实验都相对独立,过程尽可能保证完整性,保证实验 ...
- centos-testlink安装使用手册
1.新建虚拟机设置 网卡必须选择ovirtmgmt模式 2.Centos6.3系统安装 说明: 1.CentOS 6.3系统镜像有两个,安装系统只用到第一个镜像即CentOS-6.3-i386-bin ...
- 集合框架之Set学习
前言: 1.何为框架:可以理解为一个基础结构,在基础结构上进行进一步开发会变得很方便. 2.三种集合类型:集合(Set) :元素无序不可重复: 列表(List) :元素有序可重复: 映 ...
- 以太坊go-ethereum客户端查询交易列表(二)
玩过比特币的朋友都知道,比特币是可以通过api(listtransactions)查询指定地址的历史交易的.但在eth中没有提供类似的查询api.今天这篇博客就简单介绍一下如果解决这个问题. 问题 以 ...
- csu 1803(余数分类)
1803: 2016 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 565 Solved: 364[Submit][Status][Web Board ...
- Spring学习-理解IOC和依赖注入
最近刚买了一本介绍ssm框架的书,里面主要对Mybatis.spring.springmvc和redis做了很多的讲解,个人觉得虽然有的内容我看不懂,但是整体上还是不错的.最近正在学习中,一边学习一边 ...
- NIO-5补充
import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import ...
- 【WPF】淡入淡出切换页面
<NavigationWindow x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsof ...