Added in API level 21

Outline


class Outline
kotlin.Any
   ↳ android.graphics.Outline

Defines a simple shape, used for bounding graphical regions.

Can be computed for a View, or computed by a Drawable, to drive the shape of shadows cast by a View, or to clip the contents of the View.

Summary

Public constructors

Constructs an empty Outline.

Constructs an Outline with a copy of the data in src.

Public methods
Boolean

Returns whether the outline can be used to clip a View.

Float

Returns the alpha represented by the Outline.

Float

Returns the rounded rect radius, if set, or a value less than 0 if a path has been set via setPath(android.graphics.Path).

Boolean
getRect(outRect: Rect)

Populates outBounds with the outline bounds, if set, and returns true.

Boolean

Returns whether the Outline is empty.

Unit
offset(dx: Int, dy: Int)

Offsets the Outline by (dx,dy).

Unit
set(src: Outline)

Replace the contents of this Outline with the contents of src.

Unit
setAlpha(alpha: Float)

Sets the alpha represented by the Outline - the degree to which the producer is guaranteed to be opaque over the Outline's shape.

Unit
setConvexPath(convexPath: Path)

Sets the Outline to a convex path.

Unit

Sets the outline to be empty.

Unit
setOval(rect: Rect)

Convenience for setOval(int,int,int,int)

Unit
setOval(left: Int, top: Int, right: Int, bottom: Int)

Sets the outline to the oval defined by input rect.

Unit
setPath(path: Path)

Sets the Outline to a path.

Unit
setRect(rect: Rect)

Convenience for setRect(int,int,int,int)

Unit
setRect(left: Int, top: Int, right: Int, bottom: Int)

Sets the Outline to the rect defined by the input coordinates.

Unit
setRoundRect(rect: Rect, radius: Float)

Convenience for setRoundRect(int,int,int,int,float)

Unit
setRoundRect(left: Int, top: Int, right: Int, bottom: Int, radius: Float)

Sets the Outline to the rounded rect defined by the input coordinates and corner radius.

Public constructors

Outline

Added in API level 21
Outline()

Constructs an empty Outline. Call one of the setter methods to make the outline valid for use with a View.

Outline

Added in API level 21
Outline(src: Outline)

Constructs an Outline with a copy of the data in src.

Parameters
src Outline: This value cannot be null.

Public methods

canClip

Added in API level 21
fun canClip(): Boolean

Returns whether the outline can be used to clip a View.

As of API 33, all Outline shapes support clipping. Prior to API 33, only Outlines that could be represented as a rectangle, circle, or round rect supported clipping.

getAlpha

Added in API level 21
fun getAlpha(): Float

Returns the alpha represented by the Outline.

getRadius

Added in API level 24
fun getRadius(): Float

Returns the rounded rect radius, if set, or a value less than 0 if a path has been set via setPath(android.graphics.Path). A return value of 0 indicates a non-rounded rect.

Return
Float the rounded rect radius, or value < 0

getRect

Added in API level 24
fun getRect(outRect: Rect): Boolean

Populates outBounds with the outline bounds, if set, and returns true. If no outline bounds are set, or if a path has been set via setPath(android.graphics.Path), returns false.

Parameters
outRect Rect: the rect to populate with the outline bounds, if set This value cannot be null.
Return
Boolean true if outBounds was populated with outline bounds, or false if no outline bounds are set

isEmpty

Added in API level 21
fun isEmpty(): Boolean

Returns whether the Outline is empty.

Outlines are empty when constructed, or if setEmpty() is called, until a setter method is called

See Also

offset

Added in API level 22
fun offset(
    dx: Int,
    dy: Int
): Unit

Offsets the Outline by (dx,dy). Offsetting is cumulative, so additional calls to offset() will add to previous offset values. Offset only applies to the current geometry (setRect(), setPath(), etc.); setting new geometry resets any existing offset.

set

Added in API level 21
fun set(src: Outline): Unit

Replace the contents of this Outline with the contents of src.

Parameters
src Outline: Source outline to copy from. This value cannot be null.

setAlpha

Added in API level 21
fun setAlpha(alpha: Float): Unit

Sets the alpha represented by the Outline - the degree to which the producer is guaranteed to be opaque over the Outline's shape.

An alpha value of 0.0f either represents completely transparent content, or content that isn't guaranteed to fill the shape it publishes.

Content producing a fully opaque (alpha = 1.0f) outline is assumed by the drawing system to fully cover content beneath it, meaning content beneath may be optimized away.

Parameters
alpha Float: Value is between 0.0 and 1.0 inclusive

setConvexPath

Added in API level 21
Deprecated in API level 30
fun setConvexPath(convexPath: Path): Unit

Deprecated: As of android.os.Build.VERSION_CODES#Q, the restriction that the path must be convex is removed. However, the API is misnamed until android.os.Build.VERSION_CODES#R, when setPath is introduced. Use setPath instead.

Sets the Outline to a convex path.

Parameters
convexPath Path: used to construct the Outline. As of android.os.Build.VERSION_CODES#Q, it is no longer required to be convex. This value cannot be null.

setEmpty

Added in API level 21
fun setEmpty(): Unit

Sets the outline to be empty.

See Also

setOval

Added in API level 21
fun setOval(rect: Rect): Unit

Convenience for setOval(int,int,int,int)

Parameters
rect Rect: This value cannot be null.

setOval

Added in API level 21
fun setOval(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit

Sets the outline to the oval defined by input rect.

setPath

Added in API level 30
fun setPath(path: Path): Unit

Sets the Outline to a path.

Parameters
path Path: used to construct the Outline. This value cannot be null.

setRect

Added in API level 21
fun setRect(rect: Rect): Unit

Convenience for setRect(int,int,int,int)

Parameters
rect Rect: This value cannot be null.

setRect

Added in API level 21
fun setRect(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit

Sets the Outline to the rect defined by the input coordinates.

setRoundRect

Added in API level 21
fun setRoundRect(
    rect: Rect,
    radius: Float
): Unit

Convenience for setRoundRect(int,int,int,int,float)

Parameters
rect Rect: This value cannot be null.

setRoundRect

Added in API level 21
fun setRoundRect(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int,
    radius: Float
): Unit

Sets the Outline to the rounded rect defined by the input coordinates and corner radius.

Passing a zero radius is equivalent to calling setRect(int,int,int,int)