There are several drawable
1:bitmap
Supported formats:. PNG (preferred),. jpg (acceptable),. gif (discouraged).
Placing the bitmap file under the Drawable folder will be aapt automatically optimized
2:xml Bitmap
An XML bitmap are a resource defined in XML, points to a bitmap file.
The effect is an alias for a raw bitmap file
<?xml version= "1.0" encoding= "Utf-8"?>
<bitmap
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:src= "@[package:]drawable/drawable_resource"
Android:antialias=["true" | "False"]
Android:dither=["true" | "false"] jitter??
Android:filter=["true" | "False" controls whether the picture is scaled or stretched
android:gravity=["Top" | "Bottom" | "Left" | "Right" | "Center_vertical" |
"Fill_vertical" | "Center_horizontal" | "Fill_horizontal" |
"Center" | "Fill" | "Clip_vertical" | "Clip_horizontal"]
android:tilemode=["Disabled" | "Clamp" | "Repeat" | "Mirror"]/>
Defines the tile mode. When the tile mode was enabled, the bitmap is repeated.
Gravity is ignored when the tile mode is enabled.
3:nine-patch
You typically assign this type of image as the background of a View
that have at least one dimension set to "Wrap_content",
And when the View grows to accomodate the content,
The Nine-patch image is also scaled to match the size of the View
4:xml Nine-patch
An XML Nine-patch are a resource defined in XML, points to a nine-patch file.
The XML can specify dithering for the image
<?xml version= "1.0" encoding= "Utf-8"?>
<nine-patch
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:src= "@[package:]drawable/drawable_resource"
Android:dither=["true" | "false"]/> pictures are stretched when they are different from screen pixels?
5:layer List
A layerdrawable is a Drawable object, a manages an array of the other drawables.
<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" ></item>
</layer-list>
The <item></item> tag can be used to load images with <bitmap/> tags, and the image will not be stretched.
<item>
<bitmap android:src= "@drawable/image"
android:gravity= "Center"/>
</item>
6:state List
Different states show different pictures are often used for backgrounds
During Each state change, the state list was traversed top to bottom and the first item
That matches the current state is used-the selection was not based on the ' Best match, '
But simply the first item, the meets the minimum criteria of the State.
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_pressed= "true"
android:drawable= "@drawable/button_pressed"/> <!--pressed--
<item android:state_focused= "true"
android:drawable= "@drawable/button_focused"/> <!--focused--
<item android:state_hovered= "true"
android:drawable= "@drawable/button_focused"/> <!--hovered--
<item android:drawable= "@drawable/button_normal"/> <!--Default---
</selector>
What's the use of 7:level List?
A drawable that manages a number of alternate drawables, each assigned a maximum numerical value.
Setting the level value of the drawable with SetLevel () loads the drawable resource in the level list
that have a Android:maxlevel value greater than or equal to the value passed to the method.
<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>
8:transition Drawable allows two images to fade in and out (with only two pictures)
<?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>
9:inset drawable
A drawable defined in XML, insets another drawable by a specified distance.
This was useful when a view needs a background that was smaller than the view ' s actual bounds.
<inset xmlns:android= "Http://schemas.android.com/apk/res/android"
android:drawable= "@drawable/background"
android:insettop= "10DP"
android:insetleft= "10DP"/>
10:clip drawable The length, width and thickness of the original image into 10000level to cut
<?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"/>
ImageView ImageView = (ImageView) Findviewbyid (r.id.image);
Clipdrawable drawable = (clipdrawable) imageview.getdrawable ();
Drawable.setlevel (Drawable.getlevel () + 1000);
Increasing the level reduces the amount of clipping and slowly reveals the image.
11:scale drawable
A drawable defined in XML This changes the size of another drawable based on its current level.
<?xml version= "1.0" encoding= "Utf-8"?>
<scale xmlns:android= "Http://schemas.android.com/apk/res/android"
android:drawable= "@drawable/logo"
Android:scalegravity= "Center_vertical|center_horizontal"
android:scaleheight= "80%"
Android:scalewidth= "80%"/>
12:shape drawable
<shape
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:shape=["Rectangle" | "Oval" | "Line" | "Ring"] >
<corners
android:radius= "Integer"
android:topleftradius= "Integer"
android:toprightradius= "Integer"
android:bottomleftradius= "Integer"
android:bottomrightradius= "integer"/>
<gradient
android:angle= "integer" must be a multiple of 45, 0: Left to right, 90: Bottom to top
android:centerx= "Integer"
android:centery= "Integer"
Android:centercolor= "Integer"
android:endcolor= "Color"
android:gradientradius= "integer" android:type= "radial" when active, radial
android:startcolor= "Color"
android:type=["Linear" | "Radial" | "Sweep"]
Android:uselevel=["true" | "False"]/>
<padding
android:left= "Integer"
android:top= "Integer"
android:right= "Integer"
android:bottom= "integer"/>
<size default is to fill the control
Android:width= "Integer"
android:height= "integer"/>
<solid
android:color= "Color"/>
<stroke
Android:width= "Integer"
android:color= "Color"
Android:dashwidth= "integer" is matched with one of the following properties, which is valid for setting together
android:dashgap= "integer"/>
</shape>
Android drawable Summary