android drawable
Android Drawable
2023-09-14 08:58:19 时间
span >它的直接子类有
BitmapDrawable, ClipDrawable, ColorDrawable, DrawableContainer, GradientDrawable,
InsetDrawable, LayerDrawable, NinePatchDrawable, PictureDrawable, RotateDrawable,
ScaleDrawable, ShapeDrawable
间接子类有
AnimationDrawable, LevelListDrawable, PaintDrawable, StateListDrawable, TransitionDrawable
A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms. Unlike a View, a Drawable does not have any facility to receive events or otherwise interact with the user. In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn:
draw(Canvas canvas)Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
getChangingConfigurations()Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.
getTransparentRegion()Returns a Region representing the part of the Drawable that is completely transparent.
jumpToCurrentState()If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.
setBounds(int left, int top, int right, int bottom)Specify a bounding rectangle for the Drawable.
setChangingConfigurations(int configs)Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.
setDither(boolean dither)Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component.
setFilterBitmap(boolean filter)Set to true to have the drawable filter its bitmap when scaled or rotated (for drawables that use bitmaps).
onLevelChange(int level)Override this in your subclass to change appearance if you vary based on level.
onStateChange(int[] state)Override this in your subclass to change appearance if you recognize the specified state.
直接子类
BitmapDrawable A Drawable that wraps a bitmap. You can create a BitmapDrawable from a file path,
an input stream, through XML inflation, or from a Bitmap object.
它的本质是个bitmap,它提供了针对bitmap的实现。
注意:Android supports bitmap files in a three formats: .png (preferred), .jpg (acceptable), .gif (discouraged).
也是说Android把.png,.jpg,.gif都是看为BitmapDrawable,Android应该是把这三种图片转为bitmap来处理。
其实任何图片绘画时最后都是转为bitmap来处理
BitmapDrawable bitmapDrawable=(BitmapDrawable)context.getResources().getDrawable(R.drawable.icon);
Bitmap bitmap=bitmapDrawable.getBitmap();
可以通过上面的形式把BitmapDrawable转化为Bitmap
ClipDrawable A Drawable that clips another Drawable based on this Drawables current level value.
具体参照《ClipDrawable》
ColorDrawable A specialized Drawable that fills the Canvas with a specified color, with respect to the clip region.
DrawableContainer
它应该是专门用来存放Drawable的。
如何直接使用它还不知道。它不能在XML文件中定义。
它的子类AnimationDrawable, LevelListDrawable, StateListDrawable
GradientDrawable A Drawable with a color gradient for buttons, backgrounds, etc.
It can be defined in an XML file with the shape element. For more information。
InsetDrawable A Drawable that insets another Drawable by a specified distance.
LayerDrawable A Drawable that manages an array of other Drawables.
NinePatchDrawable A resizeable bitmap, with stretchable areas that you define.
它对应的是.9.png文件。关于此请参考《个性缩放图片NinePatchDrawable》 PictureDrawable Drawable subclass that wraps a Picture, allowing the picture to be used whereever a Drawable is supported.
RotateDrawable
A Drawable that can rotate another Drawable based on the current level value.
ScaleDrawable A Drawable that changes the size of another Drawable based on its current level value.
ShapeDrawable A Drawable object that draws primitive shapes. 关于此请参考《ShapeDrawable》 ColorDrawable
A specialized Drawable that fills the Canvas with a specified color,
with respect to the clip region. Note that a ColorDrawable ignores the ColorFilter.
It also ignores the Bounds, meaning it will draw everywhere in the current clip,
even if setBounds(...) was called with a smaller area.
It can be defined in an XML file with the color element.
注意1:它会忽略掉ColorFilter和Bounds,它会把整个clip区域都填充成指定的颜色。
在XML中定义和引用ColorDrawable
A color resource can also be used as a drawable in XML. For example,
when creating a state list drawable, you can reference a color resource for the android:drawable attribute
(android:drawable="@color/green
在values下的Colors.xml文件:
?xml version="1.0" encoding="UTF-8"?
resources
color name="red" #FFFF0000 /color
/resources
像引用Drawable一样引用它
TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:background="@color/red"
/
你都知道么?Android中21种drawable标签大全(下) 我们在drawable目录下可以创建很多自定义的资源,其中用的最多的应该就是selector和shape。目前在Android中有21种drawable标签,了解和利用这些标签对我们的开发有很大的帮助。这个文章我们对这21种标签做一个介绍,让大家有一个印象。 本文中有些资料取自网上,当时记录在笔记中,但是由于时间久远,忘记出处了。
你都知道么?Android中21种drawable标签大全(上) 我们在drawable目录下可以创建很多自定义的资源,其中用的最多的应该就是selector和shape。目前在Android中有21种drawable标签,了解和利用这些标签对我们的开发有很大的帮助。这个文章我们对这21种标签做一个介绍,让大家有一个印象。 本文中有些资料取自网上,当时记录在笔记中,但是由于时间久远,忘记出处了。
BitmapDrawable, ClipDrawable, ColorDrawable, DrawableContainer, GradientDrawable,
InsetDrawable, LayerDrawable, NinePatchDrawable, PictureDrawable, RotateDrawable,
ScaleDrawable, ShapeDrawable
间接子类有
AnimationDrawable, LevelListDrawable, PaintDrawable, StateListDrawable, TransitionDrawable
A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms. Unlike a View, a Drawable does not have any facility to receive events or otherwise interact with the user. In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn:
draw(Canvas canvas)Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
getChangingConfigurations()Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.
getTransparentRegion()Returns a Region representing the part of the Drawable that is completely transparent.
jumpToCurrentState()If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.
setBounds(int left, int top, int right, int bottom)Specify a bounding rectangle for the Drawable.
setChangingConfigurations(int configs)Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.
setDither(boolean dither)Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component.
setFilterBitmap(boolean filter)Set to true to have the drawable filter its bitmap when scaled or rotated (for drawables that use bitmaps).
onLevelChange(int level)Override this in your subclass to change appearance if you vary based on level.
onStateChange(int[] state)Override this in your subclass to change appearance if you recognize the specified state.
直接子类
BitmapDrawable A Drawable that wraps a bitmap. You can create a BitmapDrawable from a file path,
an input stream, through XML inflation, or from a Bitmap object.
它的本质是个bitmap,它提供了针对bitmap的实现。
注意:Android supports bitmap files in a three formats: .png (preferred), .jpg (acceptable), .gif (discouraged).
也是说Android把.png,.jpg,.gif都是看为BitmapDrawable,Android应该是把这三种图片转为bitmap来处理。
其实任何图片绘画时最后都是转为bitmap来处理
BitmapDrawable bitmapDrawable=(BitmapDrawable)context.getResources().getDrawable(R.drawable.icon);
Bitmap bitmap=bitmapDrawable.getBitmap();
可以通过上面的形式把BitmapDrawable转化为Bitmap
ClipDrawable A Drawable that clips another Drawable based on this Drawables current level value.
具体参照《ClipDrawable》
ColorDrawable A specialized Drawable that fills the Canvas with a specified color, with respect to the clip region.
DrawableContainer
它应该是专门用来存放Drawable的。
如何直接使用它还不知道。它不能在XML文件中定义。
它的子类AnimationDrawable, LevelListDrawable, StateListDrawable
GradientDrawable A Drawable with a color gradient for buttons, backgrounds, etc.
It can be defined in an XML file with the shape element. For more information。
InsetDrawable A Drawable that insets another Drawable by a specified distance.
LayerDrawable A Drawable that manages an array of other Drawables.
NinePatchDrawable A resizeable bitmap, with stretchable areas that you define.
它对应的是.9.png文件。关于此请参考《个性缩放图片NinePatchDrawable》 PictureDrawable Drawable subclass that wraps a Picture, allowing the picture to be used whereever a Drawable is supported.
RotateDrawable
A Drawable that can rotate another Drawable based on the current level value.
ScaleDrawable A Drawable that changes the size of another Drawable based on its current level value.
ShapeDrawable A Drawable object that draws primitive shapes. 关于此请参考《ShapeDrawable》 ColorDrawable
A specialized Drawable that fills the Canvas with a specified color,
with respect to the clip region. Note that a ColorDrawable ignores the ColorFilter.
It also ignores the Bounds, meaning it will draw everywhere in the current clip,
even if setBounds(...) was called with a smaller area.
It can be defined in an XML file with the color element.
注意1:它会忽略掉ColorFilter和Bounds,它会把整个clip区域都填充成指定的颜色。
在XML中定义和引用ColorDrawable
A color resource can also be used as a drawable in XML. For example,
when creating a state list drawable, you can reference a color resource for the android:drawable attribute
(android:drawable="@color/green
在values下的Colors.xml文件:
?xml version="1.0" encoding="UTF-8"?
resources
color name="red" #FFFF0000 /color
/resources
像引用Drawable一样引用它
TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:background="@color/red"
/
你都知道么?Android中21种drawable标签大全(下) 我们在drawable目录下可以创建很多自定义的资源,其中用的最多的应该就是selector和shape。目前在Android中有21种drawable标签,了解和利用这些标签对我们的开发有很大的帮助。这个文章我们对这21种标签做一个介绍,让大家有一个印象。 本文中有些资料取自网上,当时记录在笔记中,但是由于时间久远,忘记出处了。
你都知道么?Android中21种drawable标签大全(上) 我们在drawable目录下可以创建很多自定义的资源,其中用的最多的应该就是selector和shape。目前在Android中有21种drawable标签,了解和利用这些标签对我们的开发有很大的帮助。这个文章我们对这21种标签做一个介绍,让大家有一个印象。 本文中有些资料取自网上,当时记录在笔记中,但是由于时间久远,忘记出处了。
相关文章
- Android telephony_android获取真实时间
- strictmode android,Android 应用性能优化-StrictMode(严格模式)
- delphixe5 android,Delphi XE5 Android手机端转换Ansi字符串
- Android自定义View之declare-styleable记录[通俗易懂]
- android-短信验证功能,Android实现获取短信验证码的功能以及自定义GUI短信验证详解…
- android短信验证码方案,Android之短信验证码
- android listview 滑动卡顿问题解决
- Android 使用ViewPager实现左右循环滑动图片
- android系统中toast是什么_Android个人资料简单布局
- Android触摸事件_android设置按钮点击事件
- Android Studio 简单生成so文件并调用「建议收藏」
- android 锁屏壁纸时钟,桌面锁屏时钟下载-桌面锁屏时钟app安卓版v2.8.0-七度网「建议收藏」
- Android 标签栏pagerslidingtabstrip用法实例(含Demo)
- Android 自定义打包apk文件名
- 【Android 应用开发】BluetoothAdapter解析
- 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | InMemoryDexClassLoader 类加载器脱壳点总结 )
- 【ijkplayer】编译 Android 版本的 ijkplayer ③ ( 执行 compile-ffmpeg.sh clean 命令 | 下载并配置 android-ndk-r10e )
- 【ijkplayer】编译 Android 版本的 ijkplayer ⑥ ( 进入 ijkplayer-android/android 目录 | 执行 compile-ijk.sh 脚本完成编译 )
- [android] 保存文件到手机内存详解手机开发
- Android中的ProgressBar的android:indeterminate详解手机开发
- android 超轻量级数据存储类详解编程语言
- Google 将限制 Android 应用在后台访问地理位置数据
- Android漏洞扫描工具Code Arbiter
- android版本检测Android程序的版本检测与更新实现介绍
- android开发基础教程—打电话发短信
- 基于android中的各种颜色在drawable.xml中的值详解
- android,不显示标题的方法小例子
- Android创建服务之startedservice详细介绍