public
class
InsetDrawable
extends DrawableWrapper
java.lang.Object | |||
↳ | android.graphics.drawable.Drawable | ||
↳ | android.graphics.drawable.DrawableWrapper | ||
↳ | android.graphics.drawable.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.
It can be defined in an XML file with the <inset>
element. For more
information, see the guide to Drawable Resources.
XML attributes | |
---|---|
android:drawable |
Reference to a drawable resource to use for the frame. |
android:insetBottom |
|
android:insetLeft |
|
android:insetRight |
|
android:insetTop |
|
android:visible |
Provides initial visibility state of the drawable; the default value is false. |
Public constructors | |
---|---|
InsetDrawable(Drawable drawable, int inset)
Creates a new inset drawable with the specified inset. |
|
InsetDrawable(Drawable drawable, int insetLeft, int insetTop, int insetRight, int insetBottom)
Creates a new inset drawable with the specified insets. |
Public methods | |
---|---|
void
|
applyTheme(Resources.Theme t)
Applies the specified theme to this Drawable and its children. |
int
|
getIntrinsicHeight()
Returns the drawable's intrinsic height. |
int
|
getIntrinsicWidth()
Returns the drawable's intrinsic width. |
int
|
getOpacity()
Return the opacity/transparency of this Drawable. |
void
|
getOutline(Outline outline)
Called to get the drawable to populate the Outline that defines its drawing area. |
boolean
|
getPadding(Rect padding)
Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. |
void
|
inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme. |
Protected methods | |
---|---|
void
|
onBoundsChange(Rect bounds)
Override this in your subclass to change appearance if you vary based on the bounds. |
Inherited methods | |
---|---|
From
class
android.graphics.drawable.DrawableWrapper
| |
From
class
android.graphics.drawable.Drawable
| |
From
class
java.lang.Object
| |
From
interface
android.graphics.drawable.Drawable.Callback
|
Reference to a drawable resource to use for the frame. If not given, the drawable must be defined by the first child tag.
Must be a reference to another resource, in the form "@[+][package:]type:name
"
or to a theme attribute in the form "?[package:][type:]name
".
This corresponds to the global attribute
resource symbol drawable
.
Provides initial visibility state of the drawable; the default
value is false. See
setVisible(boolean, boolean)
.
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 visible
.
InsetDrawable (Drawable drawable, int inset)
Creates a new inset drawable with the specified inset.
Parameters | |
---|---|
drawable |
Drawable :
The drawable to inset. |
inset |
int :
Inset in pixels around the drawable.
|
InsetDrawable (Drawable drawable, int insetLeft, int insetTop, int insetRight, int insetBottom)
Creates a new inset drawable with the specified insets.
Parameters | |
---|---|
drawable |
Drawable :
The drawable to inset. |
insetLeft |
int :
Left inset in pixels. |
insetTop |
int :
Top inset in pixels. |
insetRight |
int :
Right inset in pixels. |
insetBottom |
int :
Bottom inset in pixels.
|
void applyTheme (Resources.Theme t)
Applies the specified theme to this Drawable and its children.
Parameters | |
---|---|
t |
Resources.Theme :
the theme to apply
|
int getIntrinsicHeight ()
Returns the drawable's intrinsic height.
Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.
Returns | |
---|---|
int |
the intrinsic height, or -1 if no intrinsic height |
int getIntrinsicWidth ()
Returns the drawable's intrinsic width.
Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.
Returns | |
---|---|
int |
the intrinsic width, or -1 if no intrinsic width |
int getOpacity ()
Return the opacity/transparency of this Drawable. The returned value is
one of the abstract format constants in
PixelFormat
:
UNKNOWN
,
TRANSLUCENT
,
TRANSPARENT
, or
OPAQUE
.
An OPAQUE drawable is one that draws all all content within its bounds, completely covering anything behind the drawable. A TRANSPARENT drawable is one that draws nothing within its bounds, allowing everything behind it to show through. A TRANSLUCENT drawable is a drawable in any other state, where the drawable will draw some, but not all, of the content within its bounds and at least some content behind the drawable will be visible. If the visibility of the drawable's contents cannot be determined, the safest/best return value is TRANSLUCENT.
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 necessarily take into account a
custom alpha or color filter that has been applied by the client through
the setAlpha(int)
or setColorFilter(ColorFilter)
methods. Some subclasses,
such as BitmapDrawable
, ColorDrawable
, and GradientDrawable
,
do account for the value of setAlpha(int)
, but the general behavior is dependent
upon the implementation of the subclass.
Returns | |
---|---|
int |
int The opacity class of the Drawable. |
void getOutline (Outline outline)
Called to get the drawable to populate the Outline that defines its drawing area.
This method is called by the default ViewOutlineProvider
to define
the outline of the View.
The default behavior defines the outline to be the bounding rectangle of 0 alpha. Subclasses that wish to convey a different shape or alpha value must override this method.
Parameters | |
---|---|
outline |
Outline
|
boolean getPadding (Rect padding)
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).
Parameters | |
---|---|
padding |
Rect
|
Returns | |
---|---|
boolean |
true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0. |
void inflate (Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme. This can't be called more than once for each Drawable. Note that framework may have called this once to create the Drawable instance from XML resource.
Parameters | |
---|---|
r |
Resources :
Resources used to resolve attribute values |
parser |
XmlPullParser :
XML parser from which to inflate this Drawable |
attrs |
AttributeSet :
Base set of attribute values |
theme |
Resources.Theme :
Theme to apply, may be null |
Throws | |
---|---|
XmlPullParserException |
|
IOException |
void onBoundsChange (Rect bounds)
Override this in your subclass to change appearance if you vary based on the bounds.
Parameters | |
---|---|
bounds |
Rect
|