A bitmap graphic file (.png, .jpg, or .gif). Creates a BitmapDrawable.
一般用于ImageView:src或以图片资源作背景
A PNG file with stretchable regions to allow image resizing based oncontent (.9.png). Creates aNinePatchDrawable.
适用于图片平铺
A Drawable that manages an array of other Drawables. These are drawnin array order, so the element with the largest index is be drawn on top.Creates a LayerDrawable.
图层的叠加
An XML file that references different bitmap graphics for differentstates (for example, to use a different image when a button is pressed).Creates a StateListDrawable.
在按钮样式中用到比较普遍,相应动作。可结合Shape使用
An XML file that defines a drawable that manages a number of alternateDrawables, each assigned a maximum numerical value. Creates a LevelListDrawable.
貌似用于显示不同的drawable resource
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/status_off"
android:maxLevel="0" />
<item
android:drawable="@drawable/status_on"
android:maxLevel="1" />
</level-list>
Once this is applied to a View, the level can be changedwith setLevel() or setImageLevel().
An XML file that defines a drawable that can cross-fade between twodrawable resources. Creates aTransitionDrawable.
用于图片切换
<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/on" />
<item android:drawable="@drawable/off" />
</transition>
Andthe following code performs a 500ms transition from the first item to thesecond:
ImageButton button = (ImageButton) findViewById(R.id.button);
TransitionDrawable drawable =(TransitionDrawable) button.getDrawable();
drawable.startTransition(500);
An XML file that defines a drawable that insets another drawable by aspecified distance. This is useful when a View needs a background drawble thatis smaller than the View's actual bounds.
用于在固定的bound里设置比该bound尺寸小的drawable resource 的位置
A drawable defined in XML that clips another drawable based on thisDrawable's current level. You can control how much the child drawable getsclipped in width and height based on the level, as well as a gravity to controlwhere it is placed in its overall container. Most often used to implementthings likeprogress bars.
EXAMPLE:
XML file saved at res/drawable/clip.xml:
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/android"
android:clipOrientation="horizontal"
android:gravity="left" />
The followinglayout XML applies the clip drawable to a View:
<ImageView
android:id="@+id/image"
android:background="@drawable/clip"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
The followingcode gets the drawable and increases the amount of clipping in order toprogressively reveal the image:
ImageView imageview = (ImageView) findViewById(R.id.image);
ClipDrawable drawable =(ClipDrawable) imageview.getDrawable();
drawable.setLevel(drawable.getLevel() + 1000);
Increasing thelevel reduces the amount of clipping and slowly reveals the image. Here it isat a level of 7000:
Note: Thedefault level is 0, which is fully clipped so the image is not visible. Whenthe level is 10,000, the image is not clipped and completely visible.
A drawable defined in XML that changes the size of another drawablebased on its current level.
An XML file that defines a geometric shape, including colors andgradients. Creates a ShapeDrawable.
常用于边框设置,比如圆角,也可用于虚线的绘制
<?xmlversion="1.0" encoding="utf-8"?>
<!-- 带圆角 白色背景 黄色色边框 长方体 -->
<layer-listxmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solidandroid:color="#FFFFFF" />
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp" />
<strokeandroid:width="2dp" android:color="@color/theme_color"/>
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
</shape>
</item>
</layer-list>
<?xmlversion="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<!--显示一条虚线,破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线-->
<stroke
android:dashGap="3dp"
android:dashWidth="3dp"
android:width="0.5dp"
android:color="@color/split_line" />
<!-- 虚线的高度 -->
<size android:height="0.5dp"/>
</shape>
Note: A color resource can also be used as a drawable inXML. For example, when creating a state list drawable, you can reference a color resource forthe android:drawable attribute (android:drawable="@color/green").