Class InsetDrawable

All Implemented Interfaces:
Drawable.Callback

public class InsetDrawable extends DrawableWrapper
A Drawable that insets another Drawable by a specified distance or fraction of the content bounds. This is used when a View needs a background that is smaller than the View's actual bounds.
  • Constructor Details

    • InsetDrawable

      public InsetDrawable(@Nullable Drawable drawable, int inset)
      Creates a new inset drawable with the specified inset.
      Parameters:
      drawable - The drawable to inset.
      inset - Inset in pixels around the drawable.
    • InsetDrawable

      public InsetDrawable(@Nullable Drawable drawable, float inset)
      Creates a new inset drawable with the specified inset.
      Parameters:
      drawable - The drawable to inset.
      inset - Inset in fraction (range: [0, 1)) of the inset content bounds.
    • InsetDrawable

      public InsetDrawable(@Nullable Drawable drawable, int insetLeft, int insetTop, int insetRight, int insetBottom)
      Creates a new inset drawable with the specified insets in pixels.
      Parameters:
      drawable - The drawable to inset.
      insetLeft - Left inset in pixels.
      insetTop - Top inset in pixels.
      insetRight - Right inset in pixels.
      insetBottom - Bottom inset in pixels.
    • InsetDrawable

      public InsetDrawable(@Nullable Drawable drawable, float insetLeftFraction, float insetTopFraction, float insetRightFraction, float insetBottomFraction)
      Creates a new inset drawable with the specified insets in fraction of the view bounds.
      Parameters:
      drawable - The drawable to inset.
      insetLeftFraction - Left inset in fraction (range: [0, 1)) of the inset content bounds.
      insetTopFraction - Top inset in fraction (range: [0, 1)) of the inset content bounds.
      insetRightFraction - Right inset in fraction (range: [0, 1)) of the inset content bounds.
      insetBottomFraction - Bottom inset in fraction (range: [0, 1)) of the inset content bounds.
  • Method Details

    • getPadding

      public boolean getPadding(@NonNull Rect padding)
      Description copied from class: Drawable
      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(int, int)).
      Overrides:
      getPadding in class DrawableWrapper
      Returns:
      true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.
    • onBoundsChange

      protected void onBoundsChange(@NonNull Rect bounds)
      Description copied from class: Drawable
      Override this in your subclass to change appearance if you vary based on the bounds.
      Overrides:
      onBoundsChange in class DrawableWrapper
    • getIntrinsicWidth

      public int getIntrinsicWidth()
      Description copied from class: Drawable
      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.

      Overrides:
      getIntrinsicWidth in class DrawableWrapper
      Returns:
      the intrinsic width, or -1 if no intrinsic width
    • getIntrinsicHeight

      public int getIntrinsicHeight()
      Description copied from class: Drawable
      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.

      Overrides:
      getIntrinsicHeight in class DrawableWrapper
      Returns:
      the intrinsic height, or -1 if no intrinsic height