java.lang.Object | ||
↳ | android.graphics.drawable.Drawable | |
↳ | android.graphics.drawable.ShapeDrawable |
Known Direct Subclasses |
A Drawable object that draws primitive shapes. A ShapeDrawable takes a Shape object and manages its presence on the screen. If no Shape is given, then the ShapeDrawable will default to a RectShape.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ShapeDrawable.ShaderFactory | Base class defines a factory object that is called each time the drawable is resized (has a new width or height). |
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
android:bottom | Bottom padding. | ||||||||||
android:color | Defines the color of the shape. | ||||||||||
android:height | Defines the height of the shape. | ||||||||||
android:left | Left padding. | ||||||||||
android:right | Right padding. | ||||||||||
android:top | Top padding. | ||||||||||
android:width | Defines the width of the shape. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ShapeDrawable constructor.
| |||||||||||
Creates a ShapeDrawable with a specified Shape.
|
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.
| |||||||||||
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.
| |||||||||||
Return in padding the insets suggested by this Drawable for placing
content inside the drawable's bounds.
| |||||||||||
Returns the Paint used to draw the shape.
| |||||||||||
Returns the ShaderFactory used by this ShapeDrawable for requesting a
Shader.
| |||||||||||
Returns the Shape of this ShapeDrawable.
| |||||||||||
Make this drawable mutable.
| |||||||||||
Set the alpha level for this drawable [0..255].
| |||||||||||
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.
| |||||||||||
Sets the intrinsic (default) height for this shape.
| |||||||||||
Sets the intrinsic (default) width for this shape.
| |||||||||||
Sets padding for the shape.
| |||||||||||
Sets padding for this shape, defined by a Rect object.
| |||||||||||
Sets a ShaderFactory to which requests for a
Shader object will be made.
| |||||||||||
Sets the Shape of this ShapeDrawable.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Subclasses override this to parse custom subelements.
| |||||||||||
Override this in your subclass to change appearance if you recognize the
specified state.
| |||||||||||
Called from the drawable's draw() method after the canvas has been set
to draw the shape at (0,0).
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.graphics.drawable.Drawable
| |||||||||||
From class java.lang.Object
|
Bottom padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
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 bottom.
Defines the color of the shape.
Must be a color value, in the form of "#rgb
", "#argb
",
"#rrggbb
", or "#aarrggbb
".
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 color.
Defines the height of the shape.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
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 height.
Left padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
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 left.
Right padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
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 right.
Top padding.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
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 top.
Defines the width of the shape.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
in (inches), mm (millimeters).
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 width.
ShapeDrawable constructor.
Creates a ShapeDrawable with a specified Shape.
s | the Shape that this ShapeDrawable should be |
---|
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.
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.
Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. Positive values move toward the center of the Drawable (set Rect.inset). Returns true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.
Returns the Paint used to draw the shape.
Returns the ShaderFactory used by this ShapeDrawable for requesting a Shader.
Returns the Shape of this ShapeDrawable.
Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification. Calling this method on a mutable Drawable will have no effect.
Set the alpha level for this drawable [0..255]. Note that this drawable also has a color in its paint, which has an alpha as well. These two values are automatically combined during drawing. Thus if the color's alpha is 75% (i.e. 192) and the drawable's alpha is 50% (i.e. 128), then the combined alpha that will be used during drawing will be 37.5% (i.e. 96).
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.
Sets the intrinsic (default) height for this shape.
height | the intrinsic height (in pixels) |
---|
Sets the intrinsic (default) width for this shape.
width | the intrinsic width (in pixels) |
---|
Sets padding for the shape.
left | padding for the left side (in pixels) |
---|---|
top | padding for the top (in pixels) |
right | padding for the right side (in pixels) |
bottom | padding for the bottom (in pixels) |
Sets padding for this shape, defined by a Rect object. Define the padding in the Rect object as: left, top, right, bottom.
Sets a ShaderFactory to which requests for a Shader object will be made.
fact | an instance of your ShaderFactory implementation |
---|
Sets the Shape of this ShapeDrawable.
Subclasses override this to parse custom subelements. If you handle it, return true, else return super.inflateTag(...).
Override this in your subclass to change appearance if you recognize the specified state.
Called from the drawable's draw() method after the canvas has been set to draw the shape at (0,0). Subclasses can override for special effects such as multiple layers, stroking, etc.