A LayerDrawable
is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top.
Each drawable is represented by an <item>
element inside a single <layer-list>
element.
res/drawable/filename.xml
The filename is used as the resource ID.
LayerDrawable
.R.drawable.filename
In XML:
@[package:]drawable/filename
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@[package:]drawable/drawable_resource" android:id="@[+][package:]id/resource_name" android:top="dimension" android:right="dimension" android:bottom="dimension" android:left="dimension" /> </layer-list>
<layer-list>
<item>
elements.
attributes:
xmlns:android
"http://schemas.android.com/apk/res/android"
.<item>
<selector>
element. Accepts child <bitmap>
elements.
attributes:
android:drawable
android:id
"@+id/name"
. The plus symbol indicates that this should be created as a new ID. You can use this identifier to retrieve and modify the drawable with View.findViewById()
orActivity.findViewById()
.android:top
android:right
android:bottom
android:left
All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list at different positions might increase the size of the View and some images scale as appropriate. To avoid scaling items in the list, use a <bitmap>
element inside the <item>
element to specify the drawable and define the gravity to something that does not scale, such as "center"
. For example, the following <item>
defines an item that scales to fit its container View:
<itemandroid:drawable="@drawable/image"/>
To avoid scaling, the following example uses a <bitmap>
element with centered gravity:
<item><bitmapandroid:src="@drawable/image"android:gravity="center"/></item>
res/drawable/layers.xml
:<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <bitmap android:src="@drawable/android_red" android:gravity="center" /> </item> <item android:top="10dp" android:left="10dp"> <bitmap android:src="@drawable/android_green" android:gravity="center" /> </item> <item android:top="20dp" android:left="20dp"> <bitmap android:src="@drawable/android_blue" android:gravity="center" /> </item> </layer-list>
Notice that this example uses a nested <bitmap>
element to define the drawable resource for each item with a "center" gravity. This ensures that none of the images are scaled to fit the size of the container, due to resizing caused by the offset images.
This layout XML applies the drawable to a View:
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/layers" />
The result is a stack of increasingly offset images:
相关推荐
Drawable资源管理图片处理
Android的Drawable运用之----LayerDrawable
使用drawable资源这方面是比较容易的,笔者学习并没有花太多时间,但是却是受益匪浅。
android修改控件外观(使用drawable资源.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
主要介绍了Android 中API之Drawable资源详解及简单实例的相关资料,需要的朋友可以参考下
editText表情输入,直接绑定drawable里面的资源文件,方便调用
我的博客《Android动画之一:Drawable Animation》附带源码
this is a sample showing how to display drawable in android.
android中的drawable集合,包括Bitmap、shape、Layer、Transition等等
主要介绍了Android 将网络的Url资源转换为Drawable资源方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
OneDrawable - 仅使用一张资源图片为 View 设置具有按下效果的背景,详细原理:http://gudong.name/2017/04/05/OneDrawable.htmlGradleAdd it in your root build.gradle at the end of repositories:allprojects...
Download drawable-xhdpi.zip 图片资源
Android所有系统资源图标android.R.drawable.xxx查看软件 源码地址:http://blog.csdn.net/dianyueneo/article/details/7197067
配合自己的文章drawable之shape的学习,将简单的例子上传至此,方便以后参考。
android安卓APP之13种Drawable位图片资源.zip
本次我们主要讲解Android平台下的各种Drawable,这里在SDK的android.graphics.drawable包下面可以看到有各种Drawable类多达十几种,它们到底之间有什么关系和区别呢?
最简单的使用Drawable资源的方法是,把图片放入Android工程的res\drawable目录下,编程环境会自动在R类里为此资源创建一个引用。你可以使用此引用访问该资源对象。譬如对应用程序的图标,在Java代码中可以用R....
DrawableStatesDemo 一个学习自定义Drawable以及学习DrawableState的demo #Author Wangjia55 () #效果图