java.lang.Object | ||
↳ | android.graphics.drawable.Drawable | |
↳ | android.graphics.drawable.BitmapDrawable |
A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object.
It can be defined in an XML file with the <bitmap>
element.
Also see the Bitmap class, which handles the management and transformation of raw bitmap graphics, and should be used when drawing to a Canvas.
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:antialias | Enables or disables antialiasing. | ||||||||||
android:dither | 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.)
Must be a boolean value, either " |
||||||||||
android:filter | Enables or disables bitmap filtering. | ||||||||||
android:gravity | Defines the gravity for the bitmap. | ||||||||||
android:src | Identifier of the bitmap file. | ||||||||||
android:tileMode | Defines the tile mode. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Draw in its bounds (set via setBounds) respecting optional effects such
as alpha (set via setAlpha) and color filter (set via setColorFilter).
| |||||||||||
Return a mask of the configuration parameters for which this drawable
mau change, requiring that it be re-created.
| |||||||||||
Get the gravity used to position/stretch the bitmap within its bounds.
| |||||||||||
Return the intrinsic height of the underlying drawable object.
| |||||||||||
Return the intrinsic width of the underlying drawable object.
| |||||||||||
Return the opacity/transparency of this Drawable.
| |||||||||||
A mutable BitmapDrawable still shares its Bitmap with any other Drawable
that comes from the same resource.
| |||||||||||
Specify an alpha value for the drawable.
| |||||||||||
Specify an optional colorFilter for the drawable.
| |||||||||||
Set to true to have the drawable dither its colors when drawn to a device
with fewer than 8-bits per color component.
| |||||||||||
Set to true to have the drawable filter its bitmap when scaled or rotated
(for drawables that use bitmaps).
| |||||||||||
Set the gravity used to position/stretch the bitmap within its bounds.
| |||||||||||
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Override this in your subclass to change appearance if you recognize the
specified state.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.graphics.drawable.Drawable
| |||||||||||
From class java.lang.Object
|
Enables or disables antialiasing.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol antialias.
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.)
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol dither.
Enables or disables bitmap filtering. Filtering is used when the bitmap is shrunk or stretched to smooth its apperance.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form
"@[package:]type:name
") or
theme attribute (in the form
"?[package:][type:]name
")
containing a value of this type.
This corresponds to the global attribute resource symbol filter.
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.
Must be one or more (separated by '|') of the following constant values.
Constant | Value | Description |
---|---|---|
top | 0x30 | Push object to the top of its container, not changing its size. |
bottom | 0x50 | Push object to the bottom of its container, not changing its size. |
left | 0x03 | Push object to the left of its container, not changing its size. |
right | 0x05 | Push object to the right of its container, not changing its size. |
center_vertical | 0x10 | Place object in the vertical center of its container, not changing its size. |
fill_vertical | 0x70 | Grow the vertical size of the object if needed so it completely fills its container. |
center_horizontal | 0x01 | Place object in the horizontal center of its container, not changing its size. |
fill_horizontal | 0x07 | Grow the horizontal size of the object if needed so it completely fills its container. |
center | 0x11 | Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. |
fill | 0x77 | Grow the horizontal and vertical size of the object if needed so it completely fills its container. |
clip_vertical | 0x80 | Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges. |
clip_horizontal | 0x08 | Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges. |
This corresponds to the global attribute resource symbol gravity.
Identifier of the bitmap file. This attribute is mandatory.
May be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
May be a color value, in the form of "#rgb
", "#argb
",
"#rrggbb
", or "#aarrggbb
".
This corresponds to the global attribute resource symbol src.
Defines the tile mode. When the tile mode is enabled, the bitmap is repeated. Gravity is ignored when the tile mode is enabled.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
disabled | -1 | Do not tile the bitmap. This is the default value. |
clamp | 0 | Replicates the edge color. |
repeat | 1 | Repeats the bitmap in both direction. |
mirror | 2 | Repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam. |
This corresponds to the global attribute resource symbol tileMode.
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
canvas | The canvas to draw into |
---|
Return a mask of the configuration parameters for which this drawable mau change, requiring that it be re-created. The default implementation returns whatever was provided through setChangingConfigurations(int) or 0 by default. Subclasses may extend this to or in the changing configurations of any other drawables they hold.
Get the gravity used to position/stretch the bitmap within its bounds. See android.view.Gravity
Return the intrinsic height of the underlying drawable object. Returns -1 if it has no intrinsic height, such as with a solid color.
Return the intrinsic width of the underlying drawable object. Returns -1 if it has no intrinsic width, such as with a solid color.
Return the opacity/transparency of this Drawable. The returned value is one of the abstract format constants in PixelFormat: UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE.
Generally a Drawable should be as conservative as possible with the value it returns. For example, if it contains multiple child drawables and only shows one of them at a time, if only one of the children is TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be returned. You can use the method resolveOpacity(int, int) to perform a standard reduction of two opacities to the appropriate single output.
Note that the returned value does not take into account a custom alpha or color filter that has been applied by the client through the setAlpha(int) or setColorFilter(ColorFilter) methods.
A mutable BitmapDrawable still shares its Bitmap with any other Drawable that comes from the same resource.
Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.
Specify an optional colorFilter for the drawable. Pass null to remove any filters.
Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component. This can improve the look on those devices, but can also slow down the drawing a little.
Set to true to have the drawable filter its bitmap when scaled or rotated (for drawables that use bitmaps). If the drawable does not use bitmaps, this call is ignored. This can improve the look when scaled or rotated, but also slows down the drawing.
Set the gravity used to position/stretch the bitmap within its bounds. See android.view.Gravity
gravity | the gravity |
---|
Override this in your subclass to change appearance if you recognize the specified state.