◎위챗 : speedseoul
http://idunnolol.com/android/drawables.html
The missing manual! Each of the top-level elements are useable in Android XML files, in /res/drawable/. Some of them are allowed to be contained in others and this is noted below.
Element | Class | Description |
---|---|---|
<animated-rotate> | AnimatedRotateDrawable | A Drawable that can animate a rotation of another Drawable. |
<animation-list> | AnimationDrawable | An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background. |
<bitmap> | BitmapDrawable | A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. |
<clip> | ClipDrawable | A Drawable that clips another Drawable based on this Drawable's current level value. You can control how much the child Drawable gets clipped in width and height based on the level, as well as a gravity to control where it is placed in its overall container. Most often used to implement things like progress bars. |
<color> | ColorDrawable | A specialized Drawable that fills the Canvas with a specified color, with respect to the clip region. |
<inset> | InsetDrawable | A Drawable that insets another Drawable by a specified distance. This is used when a View needs a background that is smaller than the View's actual bounds. |
<layer-list> | LayerDrawable | A Drawable that manages an array of other Drawables. These are drawn in array order. |
<level-list> | LevelListDrawable | A resource that manages a number of alternate Drawables, each assigned a maximum numerical value. |
<nine-patch> | NinePatchDrawable | A resizeable bitmap, with stretchable areas that you define. |
<rotate> | RotateDrawable | A Drawable that can rotate another Drawable based on the current level value. The start and end angles of rotation can be controlled to map any circular arc to the level values range. |
<scale> | ScaleDrawable | A Drawable that changes the size of another Drawable based on its current level value. |
<selector> | StateListDrawable | Lets you assign a number of graphic images to a single Drawable and swap out the visible item based on state. |
<shape> | GradientDrawable | Basic method for drawing shapes via XML. |
<transition> | TransitionDrawable | An extension of <layer-list> that is intended to cross-fade between the first and second layer. The format is exactly the same as <layer-list>. |
A Drawable that can animate a rotation of another Drawable.
Name | Type | Default | Description |
---|---|---|---|
visible | boolean | parent|true | Determines if drawable is visible. |
frameDuration | integer | 150 | The duration of each frame, in milliseconds. |
framesCount | integer | 12 | Number of frames of rotation to animate. |
pivotX | float|fraction | .5 | The pivot point, as a fraction of the width. |
pivotY | float|fraction | .5 | The pivot point, as a fraction of the height. |
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.
Name | Type | Default | Description |
---|---|---|---|
visible | boolean | parent|true | Determines if drawable is visible. |
variablePadding | boolean | false | If true, allows the drawable's padding to change based on the current state that is selected. |
oneshot | boolean | false | If true, the animation will only run a single time and then stop. |
Element | Description |
---|---|
<item> | A drawable for a frame of animation. |
A drawable for a frame of animation.
Name | Type | Default | Description |
---|---|---|---|
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
duration | integer | -1 | The duration of this frame, in milliseconds. Required. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
A Drawable that wraps a bitmap and can be tiled, stretched, or aligned.
Name | Type | Default | Description |
---|---|---|---|
src | reference | N/A | The source for the Bitmap. Required. |
antialias | boolean | false | Enables or disables antialiasing. |
filter | boolean | true | Enables or disables bitmap filtering. Filtering is used when the bitmap is shrunk or stretched to smooth its apperance. |
dither | boolean | true | Enables or disables dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with an RGB 565 screen). |
gravity | enum (top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, clip_vertical, clip_horizontal) | fill | Defines the gravity for the bitmap. The gravity indicates where to position the drawable in its container if the bitmap is smaller than the container. |
tileMode | enum (disabled, clamp, repeat, mirror) | disabled | Defines the tile mode. When the tile mode is enabled, the bitmap is repeated. Gravity is ignored when the tile mode is enabled. Values can be 'clamp' (replicates the edge color), 'repeat' (repeats the bitmap in both directions), 'mirror' (repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam). |
A Drawable that clips another Drawable based on this Drawable's current level value. You can control how much the child Drawable gets clipped in width and height based on the level, as well as a gravity to control where it is placed in its overall container. Most often used to implement things like progress bars.
Name | Type | Default | Description |
---|---|---|---|
clipOrientation | enum (horizontal, vertical) | horizontal | The orientation for the clip. |
gravity | enum (top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, clip_vertical, clip_horizontal) | left | Specifies where to clip within the drawable. |
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
A specialized Drawable that fills the Canvas with a specified color, with respect to the clip region.
Name | Type | Default | Description |
---|---|---|---|
color | color | The color to fill the Canvas with. |
A Drawable that insets another Drawable by a specified distance. This is used when a View needs a background that is smaller than the View's actual bounds.
Name | Type | Default | Description |
---|---|---|---|
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
visible | boolean | parent|true | Determines if drawable is visible. |
insetLeft | dimension | 0 | The left padding for the inset. |
insetRight | dimension | 0 | The right padding for the inset. |
insetTop | dimension | 0 | The top padding for the inset. |
insetBottom | dimension | 0 | The bottom padding for the inset. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
A Drawable that manages an array of other Drawables. These are drawn in array order.
Element | Description |
---|---|
<item> | Layer for the layer-list. |
Layer for the layer-list.
Name | Type | Default | Description |
---|---|---|---|
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
left | dimension | 0 | Left padding of this layer. |
top | dimension | 0 | Top padding of this layer. |
right | dimension | 0 | Right padding of this layer. |
bottom | dimension | 0 | Bottom padding of this layer. |
id | id | View.NO_ID | The id of this layer. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
A resource that manages a number of alternate Drawables, each assigned a maximum numerical value.
Element | Description |
---|---|
<item> | Drawable for the level. |
Drawable for the level.
Name | Type | Default | Description |
---|---|---|---|
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
minLevel | integer | 0 | The minimum level allowed for this item. |
maxLevel | integer | 0 | The maximum level allowed for this item. Required for each item tag. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
A resizeable bitmap, with stretchable areas that you define.
Name | Type | Default | Description |
---|---|---|---|
src | reference | N/A | The source for the nine patch. Required. |
dither | boolean | true | Enables or disables dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with an RGB 565 screen). |
A Drawable that can rotate another Drawable based on the current level value. The start and end angles of rotation can be controlled to map any circular arc to the level values range.
Name | Type | Default | Description |
---|---|---|---|
visible | boolean | parent|true | Determines if drawable is visible. |
fromDegrees | float | 0.0 | The initial rotation, used on the lowest level. |
toDegrees | float | 360.0 | The final rotation, used on the highest level. |
pivotX | float|fraction | .5 | The pivot point, as a fraction of the width. |
pivotY | float|fraction | .5 | The pivot point, as a fraction of the height. |
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
A Drawable that changes the size of another Drawable based on its current level value.
Name | Type | Default | Description |
---|---|---|---|
scaleWidth | string|percentage | -1 | Scale width, expressed as a percentage of the drawable's bound. The value's format is XX%. For instance: 100%, 12.5%, etc. |
scaleHeight | string|percentage | -1 | Scale height, expressed as a percentage of the drawable's bound. The value's format is XX%. For instance: 100%, 12.5%, etc. |
scaleGravity | enum (top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, clip_vertical, clip_horizontal) | left | Specifies where the drawable is positioned after scaling. |
drawable | reference | N/A | The drawable to scale; must be defined. |
Lets you assign a number of graphic images to a single Drawable and swap out the visible item based on state.
Name | Type | Default | Description |
---|---|---|---|
visible | boolean | parent|true | Determines if drawable is visible. |
variablePadding | boolean | false | If true, allows the drawable's padding to change based on the current state that is selected. |
constantSize | boolean | false | If true, the drawable's reported internal size will remain constant as the state changes; the size is the maximum of all of the states. |
dither | boolean | true | Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. |
Element | Description |
---|---|
<item> | Sets up a drawable for a particular collection of states. |
Sets up a drawable for a particular collection of states.
Name | Type | Default | Description |
---|---|---|---|
drawable | reference | null | The drawable to use for this item. Either this must be present or a drawable subelement must exist. |
state_focused | boolean | false | This state indicates the view is focused. |
state_window_focused | boolean | false | This state indicates the view's window has focus. |
state_enabled | boolean | false | This state indicates the view is enabled. |
state_checkable | boolean | false | This state indicates the view can be checked |
state_checked | boolean | false | This state indicates the view is checked. |
state_selected | boolean | false | This state indicates the view is selected. |
state_active | boolean | false | Used by SlidingTab. This state indicates that the view is active. |
state_single | boolean | false | Used by views that contain lists of items. This state indicates that the view is showing only one item. |
state_first | boolean | false | Used by views that contain lists of items. This state indicates that the view is showing the first item. |
state_middle | boolean | false | Used by views that contain lists of items. This state indicates that the view is showing the middle item. |
state_last | boolean | false | Used by views that contain lists of items. This state indicates that the view is showing the last item. |
state_pressed | boolean | false | Used by views that contain lists of items. This state indicates that the view is pressed. |
Element | Description |
---|---|
<[any drawable tag]> | Any drawable xml. Either this must be present or the 'drawable' attribute must be set. |
Any drawable xml. Either this must be present or the 'drawable' attribute must be set.
Basic method for drawing shapes via XML.
Name | Type | Default | Description |
---|---|---|---|
visible | boolean | parent|true | Determines if drawable is visible. |
shape | enum (rectangle, oval, line, ring) | rectangle | Determines the shape: rectangle (shape is a rectangle, possibly with rounded corners); oval (shape is an ellipse); line (shape is a line); ring (shape is a ring). |
innerRadiusRatio | float | 3.0 | Only valid if shape == 'ring'. Inner radius of the ring expressed as a ratio of the ring's width. For instance, if innerRadiusRatio=3, then the inner radius equals the ring's width divided by 3. This value is ignored if innerRadius is defined. |
innerRadius | float | -1 | Only valid if shape == 'ring'. Inner radius of the ring. When defined, innerRadiusRatio is ignored. When undefined, innerRadiusRatio's default is used. |
thicknessRatio | float | 9.0 | Only valid if shape == 'ring'. Thickness of the ring expressed as a ratio of the ring's width. For instance, if thicknessRatio=9, then the thickness equals the ring's width divided by 9. This value is ignored if thickness is defined. Default value is 9. |
thickness | float | -1 | Only valid if shape == 'ring'. Thickness of the ring. When defined, thicknessRatio is ignored. When undefined, thicknessRatio's default is used. |
useLevel | boolean | true | Only valid if shape == 'ring'. Allows one to draw only part of the ring (arc-wise), by modifying the drawable's level. This setting only makes sense in context of a <level-list> (LevelListDrawable). |
Element | Description |
---|---|
<size> | Determines the size of the shape. |
<gradient> | Adds a background gradient to the shape. |
<solid> | Adds a solid background color to the shape. Overides gradient element. |
<stroke> | Adds a border to the shape. |
<corners> | Adds rounded corners to the shape. |
<padding> | The padding for the content within this drawable. (Does not pad graphics in any way.) |
Determines the size of the shape.
Name | Type | Default | Description |
---|---|---|---|
width | dimension | -1 | Width of the shape. |
height | dimension | -1 | Height of the shape. |
Adds a background gradient to the shape.
Name | Type | Default | Description |
---|---|---|---|
startColor | color | 0 | The color at the start of the gradient. |
centerColor | color | 0 | The color in the center of the gradient. Optional; if not included, there is no center color. |
endColor | color | 0 | The color at the end of the gradient. |
type | enum (linear, radial, sweep) | linear | Determines the type of gradient. |
centerX | float|fraction | .5 | Determines the location of the centerColor. Ranges from 0 to 1. Ignored if centerColor is undefined. |
centerY | float|fraction | .5 | Determines the location of the centerColor. Ranges from 0 to 1. Ignored if centerColor is undefined. |
angle | float | 0 | Only valid if type == 'linear'. Determines the angle of a linear gradient. Must be a multiple of 45 degrees. |
gradientRadius | float|fraction | N/A | Only valid if type == 'radial' or 'sweep'. Required if type == 'radial'. Determines the radius of the gradient. |
useLevel | boolean | false | Determines the amount of the gradient to be drawn, based on the level of the shape. Affects all three gradient types. |
Adds a solid background color to the shape. Overides gradient element.
Name | Type | Default | Description |
---|---|---|---|
color | color | 0 | The color of the background. |
Adds a border to the shape.
Name | Type | Default | Description |
---|---|---|---|
width | dimension | 0 | The width of the stroke. |
color | color | 0 | The color of the stroke. |
dashWidth | dimension | 0 | The width of each dash. Ignored unless dashGap is also defined. |
dashGap | dimension | 0 | The width of gaps between eahc dash. Ignored unless dashWidth is also defined. |
Adds rounded corners to the shape.
Name | Type | Default | Description |
---|---|---|---|
radius | dimension | 0 | The radius of every corner. |
topLeftRadius | dimension | radius | Determines the radius of the top left corner. Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes. |
topRightRadius | dimension | radius | Determines the radius of the top right corner. Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes. |
bottomLeftRadius | dimension | radius | Determines the radius of the bottom left corner (buggy; is actually bottom right corner). Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes. |
bottomRightRadius | dimension | radius | Determines the radius of the bottom right corner (buggy; is actually bottom left corner). Ignored unless radius for all corners is defined, either through 'radius' or the other corners' attributes. |
The padding for the content within this drawable. (Does not pad graphics in any way.)
Name | Type | Default | Description |
---|---|---|---|
left | dimension | 0 | Left padding. |
top | dimension | 0 | Top padding. |
right | dimension | 0 | Right padding. |
bottom | dimension | 0 | Bottom padding. |
An extension of <layer-list> that is intended to cross-fade between the first and second layer. The format is exactly the same as <layer-list>.