Outline


public final class Outline
extends Object

java.lang.Object
   ↳ 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

Outline()

Constructs an empty Outline.

Outline(Outline src)

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

Public methods

boolean canClip()

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

float getAlpha()

Returns the alpha represented by the Outline.

float getRadius()

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(Rect outRect)

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

boolean isEmpty()

Returns whether the Outline is empty.

void offset(int dx, int dy)

Offsets the Outline by (dx,dy).

void set(Outline src)

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

void setAlpha(float alpha)

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

void setConvexPath(Path convexPath)

This method was deprecated in API level 30. As of Build.VERSION_CODES.Q, the restriction that the path must be convex is removed. However, the API is misnamed until Build.VERSION_CODES.R, when setPath(Path) is introduced. Use setPath(Path) instead.

void setEmpty()

Sets the outline to be empty.

void setOval(Rect rect)

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

void setOval(int left, int top, int right, int bottom)

Sets the outline to the oval defined by input rect.

void setPath(Path path)

Sets the Outline to a path.

void setRect(Rect rect)

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

void setRect(int left, int top, int right, int bottom)

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

void setRoundRect(Rect rect, float radius)

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

void setRoundRect(int left, int top, int right, int bottom, float radius)

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

Inherited methods

Public constructors

Outline

Added in API level 21
public 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
public Outline (Outline src)

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
public boolean canClip ()

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.

Returns
boolean

getAlpha

Added in API level 21
public float getAlpha ()

Returns the alpha represented by the Outline.

Returns
float

getRadius

Added in API level 24
public float getRadius ()

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.

Returns
float the rounded rect radius, or value < 0

getRect

Added in API level 24
public boolean getRect (Rect outRect)

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.

Returns
boolean true if outBounds was populated with outline bounds, or false if no outline bounds are set

isEmpty

Added in API level 21
public boolean isEmpty ()

Returns whether the Outline is empty.

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

Returns
boolean

See also:

offset

Added in API level 22
public void offset (int dx, 
                int dy)

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.

Parameters
dx int

dy int

set

Added in API level 21
public void set (Outline src)

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
public void setAlpha (float alpha)

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
public void setConvexPath (Path convexPath)

This method was deprecated in API level 30.
As of Build.VERSION_CODES.Q, the restriction that the path must be convex is removed. However, the API is misnamed until Build.VERSION_CODES.R, when setPath(Path) is introduced. Use setPath(Path) instead.

Sets the Outline to a convex path.

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

setEmpty

Added in API level 21
public void setEmpty ()

Sets the outline to be empty.

See also:

setOval

Added in API level 21
public void setOval (Rect rect)

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

Parameters
rect Rect: This value cannot be null.

setOval

Added in API level 21
public void setOval (int left, 
                int top, 
                int right, 
                int bottom)

Sets the outline to the oval defined by input rect.

Parameters
left int

top int

right int

bottom int

setPath

Added in API level 30
public void setPath (Path path)

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
public void setRect (Rect rect)

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

Parameters
rect Rect: This value cannot be null.

setRect

Added in API level 21
public void setRect (int left, 
                int top, 
                int right, 
                int bottom)

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

Parameters
left int

top int

right int

bottom int

setRoundRect

Added in API level 21
public void setRoundRect (Rect rect, 
                float radius)

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

Parameters
rect Rect: This value cannot be null.

radius float

setRoundRect

Added in API level 21
public void setRoundRect (int left, 
                int top, 
                int right, 
                int bottom, 
                float radius)

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)

Parameters
left int

top int

right int

bottom int

radius float