Added in API level 29

RenderNode


class RenderNode
kotlin.Any
   ↳ android.graphics.RenderNode

RenderNode is used to build hardware accelerated rendering hierarchies. Each RenderNode contains both a display list as well as a set of properties that affect the rendering of the display list. RenderNodes are used internally for all Views by default and are not typically used directly.

RenderNodes are used to divide up the rendering content of a complex scene into smaller pieces that can then be updated individually more cheaply. Updating part of the scene only needs to update the display list or properties of a small number of RenderNode instead of redrawing everything from scratch. A RenderNode only needs its display list re-recorded when its content alone should be changed. RenderNodes can also be transformed without re-recording the display list through the transform properties.

A text editor might for instance store each paragraph into its own RenderNode. Thus when the user inserts or removes characters, only the display list of the affected paragraph needs to be recorded again.

Hardware acceleration

RenderNodes can be drawn using a RecordingCanvas. They are not supported in software. Always make sure that the android.graphics.Canvas you are using to render a display list is hardware accelerated using android.graphics.Canvas#isHardwareAccelerated().

Creating a RenderNode

RenderNode renderNode = new RenderNode("myRenderNode");
      renderNode.setPosition(0, 0, 50, 50); // Set the size to 50x50
      RecordingCanvas canvas = renderNode.beginRecording();
      try {
          // Draw with the canvas
          canvas.drawRect(...);
      } finally {
          renderNode.endRecording();
      }

Drawing a RenderNode in a View

protected void onDraw(Canvas canvas) {
          if (canvas.isHardwareAccelerated()) {
              // Check that the RenderNode has a display list, re-recording it if it does not.
              if (!myRenderNode.hasDisplayList()) {
                  updateDisplayList(myRenderNode);
              }
              // Draw the RenderNode into this canvas.
              canvas.drawRenderNode(myRenderNode);
          }
      }

Releasing resources

This step is not mandatory but recommended if you want to release resources held by a display list as soon as possible. Most significantly any bitmaps it may contain.

// Discards the display list content allowing for any held resources to be released.
      // After calling this
      renderNode.discardDisplayList();

Properties

In addition, a RenderNode offers several properties, such as setScaleX(float) or setTranslationX(float), that can be used to affect all the drawing commands recorded within. For instance, these properties can be used to move around a large number of images without re-issuing all the individual canvas.drawBitmap() calls.

private void createDisplayList() {
          mRenderNode = new RenderNode("MyRenderNode");
          mRenderNode.setPosition(0, 0, width, height);
          RecordingCanvas canvas = mRenderNode.beginRecording();
          try {
              for (Bitmap b : mBitmaps) {
                  canvas.drawBitmap(b, 0.0f, 0.0f, null);
                  canvas.translate(0.0f, b.getHeight());
              }
          } finally {
              mRenderNode.endRecording();
          }
      }
 
      protected void onDraw(Canvas canvas) {
          if (canvas.isHardwareAccelerated())
              canvas.drawRenderNode(mRenderNode);
          }
      }
 
      private void moveContentBy(int x) {
           // This will move all the bitmaps recorded inside the display list
           // by x pixels to the right and redraw this view. All the commands
           // recorded in createDisplayList() won't be re-issued, only onDraw()
           // will be invoked and will execute very quickly
           mRenderNode.offsetLeftAndRight(x);
           invalidate();
      }

A few of the properties may at first appear redundant, such as setElevation(float) and setTranslationZ(float). The reason for these duplicates are to allow for a separation between static & transient usages. For example consider a button that raises from 2dp to 8dp when pressed. To achieve that an application may decide to setElevation(2dip), and then on press to animate setTranslationZ to 6dip. Combined this achieves the final desired 8dip value, but the animation need only concern itself with animating the lift from press without needing to know the initial starting value. setTranslationX(float) and setTranslationY(float) are similarly provided for animation uses despite the functional overlap with setPosition(android.graphics.Rect).

The RenderNode's transform matrix is computed at render time as follows:

Matrix transform = new Matrix();
      transform.setTranslate(renderNode.getTranslationX(), renderNode.getTranslationY());
      transform.preRotate(renderNode.getRotationZ(),
              renderNode.getPivotX(), renderNode.getPivotY());
      transform.preScale(renderNode.getScaleX(), renderNode.getScaleY(),
              renderNode.getPivotX(), renderNode.getPivotY());
The current canvas transform matrix, which is translated to the RenderNode's position, is then multiplied by the RenderNode's transform matrix. Therefore the ordering of calling property setters does not affect the result. That is to say that:
renderNode.setTranslationX(100);
      renderNode.setScaleX(100);
is equivalent to:
renderNode.setScaleX(100);
      renderNode.setTranslationX(100);

Threading

RenderNode may be created and used on any thread but they are not thread-safe. Only a single thread may interact with a RenderNode at any given time. It is critical that the RenderNode is only used on the same thread it is drawn with. For example when using RenderNode with a custom View, then that RenderNode must only be used from the UI thread.

When to re-render

Many of the RenderNode mutation methods, such as setTranslationX(float), return a boolean indicating if the value actually changed or not. This is useful in detecting if a new frame should be rendered or not. A typical usage would look like:

public void translateTo(int x, int y) {
          boolean needsUpdate = myRenderNode.setTranslationX(x);
          needsUpdate |= myRenderNode.setTranslationY(y);
          if (needsUpdate) {
              myOwningView.invalidate();
          }
      }
This is marginally faster than doing a more explicit up-front check if the value changed by comparing the desired value against getTranslationX() as it minimizes JNI transitions. The actual mechanism of requesting a new frame to be rendered will depend on how this RenderNode is being drawn. If it's drawn to a containing View, as in the above snippet, then simply invalidating that View works. If instead the RenderNode is being drawn to a Canvas directly such as with Surface.lockHardwareCanvas() then a new frame needs to be drawn by calling Surface.lockHardwareCanvas(), re-drawing the root RenderNode or whatever top-level content is desired, and finally calling Surface.unlockCanvasAndPost(Canvas).

Summary

Public constructors

Creates a new RenderNode that can be used to record batches of drawing operations, and store / apply render properties when drawn.

Public methods
RecordingCanvas

Same as beginRecording(int,int) with the width & height set to the RenderNode's own width & height.

RecordingCanvas
beginRecording(width: Int, height: Int)

Starts recording a display list for the render node.

Long

Gets the approximate memory usage of the RenderNode for debug purposes.

Unit

Reset native resources.

Unit

` Ends the recording for this display list.

Float

Returns the translucency level of this display list.

Int

Int

Gets the bottom position for the RenderNode.

Float

Returns the distance in Z of the camera for this RenderNode

Boolean

Returns whether or not the RenderNode is clipping to its bounds.

Boolean

See setClipToOutline(boolean)

Float

See setElevation(float)

Int

Gets the height of the RenderNode, which is the bottom - top.

Unit

Gets the current transform inverted.

Int

Gets the left position for the RenderNode.

Unit
getMatrix(outMatrix: Matrix)

Gets the current transform matrix

Float

Returns the pivot value for this display list on the X axis, in pixels.

Float

Returns the pivot value for this display list on the Y axis, in pixels.

Int

Gets the right position for the RenderNode.

Float

Returns the rotation value for this display list around the X axis, in degrees.

Float

Returns the rotation value for this display list around the Y axis, in degrees.

Float

Returns the rotation value for this display list around the Z axis, in degrees.

Float

Returns the scale value for this display list on the X axis.

Float

Returns the scale value for this display list on the Y axis.

Int

Int

Gets the top position for the RenderNode.

Float

Returns the translation value for this display list on the X axis, in pixels.

Float

Returns the translation value for this display list on the Y axis, in pixels.

Float

Returns the translation value for this display list on the Z axis.

Long

Returns the unique ID that identifies this RenderNode.

Boolean

Gets whether or not a compositing layer is forced to be used.

Int

Gets the width of the RenderNode, which is the right - left.

Boolean

Returns whether the RenderNode has a display list.

Boolean

Whether or not the RenderNode has an identity transform.

Boolean

Indicates whether the content of this display list overlaps.

Boolean

Checks if the RenderNode has a shadow.

Boolean

See setForceDarkAllowed(boolean)

Boolean

Boolean

Offsets the left and right positions for the RenderNode

Boolean

Offsets the top and bottom values for the RenderNode

Boolean

Clears any pivot previously set by a call to setPivotX(float) or setPivotY(float).

Boolean
setAlpha(alpha: Float)

Sets the translucency level for the display list.

Boolean

Sets the color of the ambient shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas.enableZ() section.

Boolean

Sets the distance along the Z axis (orthogonal to the X/Y plane on which RenderNodes are drawn) from the camera to this RenderNode.

Boolean
setClipRect(rect: Rect?)

Sets an additional clip on the RenderNode.

Boolean
setClipToBounds(clipToBounds: Boolean)

Set whether the Render node should clip itself to its bounds.

Boolean
setClipToOutline(clipToOutline: Boolean)

Enables or disables clipping to the outline.

Boolean

Sets the base elevation of this RenderNode in pixels

Boolean

Sets whether or not to allow force dark to apply to this RenderNode.

Boolean
setHasOverlappingRendering(hasOverlappingRendering: Boolean)

Sets whether the display list renders content which overlaps.

Boolean
setOutline(outline: Outline?)

Sets the outline, defining the shape that casts a shadow, and the path to be clipped if setClipToOutline is set.

Boolean
setPivotX(pivotX: Float)

Sets the pivot value for the display list on the X axis

Boolean
setPivotY(pivotY: Float)

Sets the pivot value for the display list on the Y axis

Boolean
setPosition(position: Rect)

Sets the position of the RenderNode.

Boolean
setPosition(left: Int, top: Int, right: Int, bottom: Int)

Sets the position of the RenderNode.

Boolean
setProjectBackwards(shouldProject: Boolean)

Sets whether the RenderNode should be drawn immediately after the closest ancestor RenderNode containing a projection receiver.

Boolean

Sets whether the RenderNode is a projection receiver.

Boolean
setRenderEffect(renderEffect: RenderEffect?)

Configure the android.graphics.RenderEffect to apply to this RenderNode.

Boolean
setRotationX(rotationX: Float)

Sets the rotation value for the display list around the X axis.

Boolean
setRotationY(rotationY: Float)

Sets the rotation value for the display list around the Y axis.

Boolean
setRotationZ(rotation: Float)

Sets the rotation value for the display list around the Z axis.

Boolean
setScaleX(scaleX: Float)

Sets the scale value for the display list on the X axis.

Boolean
setScaleY(scaleY: Float)

Sets the scale value for the display list on the Y axis.

Boolean

Sets the color of the spot shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas.enableZ() section.

Boolean
setTranslationX(translationX: Float)

Sets the translation value for the display list on the X axis.

Boolean
setTranslationY(translationY: Float)

Sets the translation value for the display list on the Y axis.

Boolean
setTranslationZ(translationZ: Float)

Sets the translation value for the display list on the Z axis.

Boolean
setUseCompositingLayer(forceToLayer: Boolean, paint: Paint?)

Controls whether or not to force this RenderNode to render to an intermediate buffer.

Public constructors

RenderNode

Added in API level 29
RenderNode(name: String?)

Creates a new RenderNode that can be used to record batches of drawing operations, and store / apply render properties when drawn.

Parameters
name String?: The name of the RenderNode, used for debugging purpose. May be null.

Public methods

beginRecording

Added in API level 29
fun beginRecording(): RecordingCanvas

Same as beginRecording(int,int) with the width & height set to the RenderNode's own width & height. The RenderNode's width & height may be set with setPosition(int,int,int,int).

Return
RecordingCanvas A canvas to record drawing operations. This value cannot be null.
Exceptions
java.lang.IllegalStateException If a recording is already in progress. That is, the previous call to beginRecording(int,int) did not call endRecording().

beginRecording

Added in API level 29
fun beginRecording(
    width: Int,
    height: Int
): RecordingCanvas

Starts recording a display list for the render node. All operations performed on the returned canvas are recorded and stored in this display list. endRecording() must be called when the recording is finished in order to apply the updated display list. Failing to call endRecording() will result in an IllegalStateException if beginRecording(int,int) is called again.

Parameters
width Int: The width of the recording viewport. This will not alter the width of the RenderNode itself, that must be set with setPosition(android.graphics.Rect).
height Int: The height of the recording viewport. This will not alter the height of the RenderNode itself, that must be set with setPosition(android.graphics.Rect).
Return
RecordingCanvas A canvas to record drawing operations. This value cannot be null.
Exceptions
java.lang.IllegalStateException If a recording is already in progress. That is, the previous call to beginRecording(int,int) did not call endRecording().

computeApproximateMemoryUsage

Added in API level 29
fun computeApproximateMemoryUsage(): Long

Gets the approximate memory usage of the RenderNode for debug purposes. Does not include the memory usage of any child RenderNodes nor any bitmaps, only the memory usage of this RenderNode and any data it owns.
Value is a non-negative number of bytes.

Return
Long Approximate memory usage in bytes. Value is a non-negative number of bytes.

discardDisplayList

Added in API level 29
fun discardDisplayList(): Unit

Reset native resources. This is called when cleaning up the state of display lists during destruction of hardware resources, to ensure that we do not hold onto obsolete resources after related resources are gone.

endRecording

Added in API level 29
fun endRecording(): Unit

` Ends the recording for this display list. Calling this method marks the display list valid and hasDisplayList() will return true.

getAlpha

Added in API level 29
fun getAlpha(): Float

Returns the translucency level of this display list.

Return
Float A value between 0.0f and 1.0f

See Also

getAmbientShadowColor

Added in API level 29
fun getAmbientShadowColor(): Int
Return
Int The shadow color set by setAmbientShadowColor(int), or black if nothing was set

getBottom

Added in API level 29
fun getBottom(): Int

Gets the bottom position for the RenderNode.

Return
Int the bottom position in pixels

getCameraDistance

Added in API level 29
fun getCameraDistance(): Float

Returns the distance in Z of the camera for this RenderNode

Return
Float the distance along the Z axis in pixels. Value is between 0.0f and Float.MAX_VALUE inclusive

getClipToBounds

Added in API level 29
fun getClipToBounds(): Boolean

Returns whether or not the RenderNode is clipping to its bounds. See setClipToBounds(boolean) and setPosition(int,int,int,int)

Return
Boolean true if the render node clips to its bounds, false otherwise.

getClipToOutline

Added in API level 29
fun getClipToOutline(): Boolean

See setClipToOutline(boolean)

Return
Boolean True if this RenderNode clips to its outline, false otherwise

getElevation

Added in API level 29
fun getElevation(): Float

See setElevation(float)

Return
Float The RenderNode's current elevation

getHeight

Added in API level 29
fun getHeight(): Int

Gets the height of the RenderNode, which is the bottom - top.

Return
Int the height of the RenderNode

getInverseMatrix

Added in API level 29
fun getInverseMatrix(outMatrix: Matrix): Unit

Gets the current transform inverted. This is a faster way to do the otherwise equivalent getMatrix(android.graphics.Matrix) followed by Matrix.invert(Matrix)

Parameters
outMatrix Matrix: The matrix to store the inverse transform of the RenderNode This value cannot be null.

getLeft

Added in API level 29
fun getLeft(): Int

Gets the left position for the RenderNode.

Return
Int the left position in pixels

getMatrix

Added in API level 29
fun getMatrix(outMatrix: Matrix): Unit

Gets the current transform matrix

Parameters
outMatrix Matrix: The matrix to store the transform of the RenderNode This value cannot be null.

getPivotX

Added in API level 29
fun getPivotX(): Float

Returns the pivot value for this display list on the X axis, in pixels.

getPivotY

Added in API level 29
fun getPivotY(): Float

Returns the pivot value for this display list on the Y axis, in pixels.

getRight

Added in API level 29
fun getRight(): Int

Gets the right position for the RenderNode.

Return
Int the right position in pixels

getRotationX

Added in API level 29
fun getRotationX(): Float

Returns the rotation value for this display list around the X axis, in degrees.

getRotationY

Added in API level 29
fun getRotationY(): Float

Returns the rotation value for this display list around the Y axis, in degrees.

getRotationZ

Added in API level 29
fun getRotationZ(): Float

Returns the rotation value for this display list around the Z axis, in degrees.

getScaleX

Added in API level 29
fun getScaleX(): Float

Returns the scale value for this display list on the X axis.

getScaleY

Added in API level 29
fun getScaleY(): Float

Returns the scale value for this display list on the Y axis.

getSpotShadowColor

Added in API level 29
fun getSpotShadowColor(): Int
Return
Int The shadow color set by setSpotShadowColor(int), or black if nothing was set

getTop

Added in API level 29
fun getTop(): Int

Gets the top position for the RenderNode.

Return
Int the top position in pixels

getTranslationX

Added in API level 29
fun getTranslationX(): Float

Returns the translation value for this display list on the X axis, in pixels.

getTranslationY

Added in API level 29
fun getTranslationY(): Float

Returns the translation value for this display list on the Y axis, in pixels.

getTranslationZ

Added in API level 29
fun getTranslationZ(): Float

Returns the translation value for this display list on the Z axis.

getUniqueId

Added in API level 29
fun getUniqueId(): Long

Returns the unique ID that identifies this RenderNode. This ID is unique for the lifetime of the process. IDs are reset on process death, and are unique only within the process. This ID is intended to be used with debugging tools to associate a particular RenderNode across different debug dumping & inspection tools. For example a View layout inspector should include the unique ID for any RenderNodes that it owns to associate the drawing content with the layout content.

Return
Long the unique ID for this RenderNode

getUseCompositingLayer

Added in API level 29
fun getUseCompositingLayer(): Boolean

Gets whether or not a compositing layer is forced to be used. The default & recommended is false, as it is typically faster to avoid using compositing layers. See setUseCompositingLayer(boolean,android.graphics.Paint).

Return
Boolean true if a compositing layer is forced, false otherwise

getWidth

Added in API level 29
fun getWidth(): Int

Gets the width of the RenderNode, which is the right - left.

Return
Int the width of the RenderNode

hasDisplayList

Added in API level 29
fun hasDisplayList(): Boolean

Returns whether the RenderNode has a display list. If this returns false, the RenderNode should be re-recorded with beginRecording() and endRecording(). A RenderNode without a display list may still be drawn, however it will have no impact on the rendering content until its display list is updated. When a RenderNode is no longer drawn by anything the system may automatically invoke discardDisplayList(). It is therefore important to ensure that hasDisplayList() is true on a RenderNode prior to drawing it. See discardDisplayList()

Return
Boolean boolean true if this RenderNode has a display list, false otherwise.

hasIdentityMatrix

Added in API level 29
fun hasIdentityMatrix(): Boolean

Whether or not the RenderNode has an identity transform. This is a faster way to do the otherwise equivalent getMatrix(android.graphics.Matrix) Matrix.isIdentity() as it doesn't require copying the Matrix first, thus minimizing overhead.

Return
Boolean true if the RenderNode has an identity transform, false otherwise

hasOverlappingRendering

Added in API level 29
fun hasOverlappingRendering(): Boolean

Indicates whether the content of this display list overlaps.

Return
Boolean True if this display list renders content which overlaps, false otherwise.

hasShadow

Added in API level 29
fun hasShadow(): Boolean

Checks if the RenderNode has a shadow. That is, if the combination of getElevation() and getTranslationZ() is greater than zero, there is an Outline set with a valid shadow caster path, and the provided outline has a non-zero Outline.getAlpha().

Return
Boolean True if this RenderNode has a shadow, false otherwise

isForceDarkAllowed

Added in API level 29
fun isForceDarkAllowed(): Boolean

See setForceDarkAllowed(boolean)

Return
Boolean true if force dark is allowed (default), false if it is disabled

isPivotExplicitlySet

Added in API level 29
fun isPivotExplicitlySet(): Boolean
Return
Boolean Whether or not a pivot was explicitly set with setPivotX(float) or setPivotY(float). If no pivot has been set then the pivot will be the center of the RenderNode.

offsetLeftAndRight

Added in API level 29
fun offsetLeftAndRight(offset: Int): Boolean

Offsets the left and right positions for the RenderNode

Parameters
offset Int: The amount that the left and right positions are offset in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

offsetTopAndBottom

Added in API level 29
fun offsetTopAndBottom(offset: Int): Boolean

Offsets the top and bottom values for the RenderNode

Parameters
offset Int: The amount that the left and right positions are offset in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

resetPivot

Added in API level 29
fun resetPivot(): Boolean

Clears any pivot previously set by a call to setPivotX(float) or setPivotY(float). After calling this isPivotExplicitlySet() will be false and the pivot used for rotation will return to default of being centered on the view.

Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setAlpha

Added in API level 29
fun setAlpha(alpha: Float): Boolean

Sets the translucency level for the display list.

Parameters
alpha Float: The translucency of the display list, must be a value between 0.0f and 1.0f
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setAmbientShadowColor

Added in API level 29
fun setAmbientShadowColor(color: Int): Boolean

Sets the color of the ambient shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas.enableZ() section.

By default the shadow color is black. Generally, this color will be opaque so the intensity of the shadow is consistent between different RenderNodes with different colors.

The opacity of the final ambient shadow is a function of the shadow caster height, the alpha channel of the outlineAmbientShadowColor (typically opaque), and the android.R.attr#ambientShadowAlpha theme attribute.

Parameters
color Int: The color this RenderNode will cast for its elevation shadow.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setCameraDistance

Added in API level 29
fun setCameraDistance(distance: Float): Boolean

Sets the distance along the Z axis (orthogonal to the X/Y plane on which RenderNodes are drawn) from the camera to this RenderNode. The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.

The distance of the camera from the drawing plane can have an affect on the perspective distortion of the RenderNode when it is rotated around the x or y axis. For example, a large distance will result in a large viewing angle, and there will not be much perspective distortion of the view as it rotates. A short distance may cause much more perspective distortion upon rotation, and can also result in some drawing artifacts if the rotated view ends up partially behind the camera (which is why the recommendation is to use a distance at least as far as the size of the view, if the view is to be rotated.)

The distance is expressed in pixels and must always be positive

Parameters
distance Float: The distance in pixels, must always be positive Value is between 0.0f and Float.MAX_VALUE inclusive
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setClipRect

Added in API level 29
fun setClipRect(rect: Rect?): Boolean

Sets an additional clip on the RenderNode. If null, the extra clip is removed from the RenderNode. If non-null, the RenderNode will be clipped to this rect. In addition if setClipToBounds(boolean) is true, then the RenderNode will be clipped to the intersection of this rectangle and the bounds of the render node, which is set with setPosition(android.graphics.Rect).

This is equivalent to do a Canvas.clipRect(Rect) at the start of this RenderNode's display list. However, as this is a property of the RenderNode instead of part of the display list it can be more easily animated for transient additional clipping. An example usage of this would be the android.transition.ChangeBounds transition animation with the resizeClip=true option.

Parameters
rect Rect?: the bounds to clip to. If null, the additional clip is removed.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setClipToBounds

Added in API level 29
fun setClipToBounds(clipToBounds: Boolean): Boolean

Set whether the Render node should clip itself to its bounds. This defaults to true, and is useful to the renderer in enable quick-rejection of chunks of the tree as well as better partial invalidation support. Clipping can be further restricted or controlled through the combination of this property as well as setClipRect(android.graphics.Rect), which allows for a different clipping rectangle to be used in addition to or instead of the setPosition(int,int,int,int) or the RenderNode.

Parameters
clipToBounds Boolean: true if the display list should clip to its bounds, false otherwise.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setClipToOutline

Added in API level 29
fun setClipToOutline(clipToOutline: Boolean): Boolean

Enables or disables clipping to the outline.

Parameters
clipToOutline Boolean: true if clipping to the outline.
Return
Boolean True if the clipToOutline value changed, false if previous value matched the new value.

setElevation

Added in API level 29
fun setElevation(lift: Float): Boolean

Sets the base elevation of this RenderNode in pixels

Parameters
lift Float: the elevation in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setForceDarkAllowed

Added in API level 29
fun setForceDarkAllowed(allow: Boolean): Boolean

Sets whether or not to allow force dark to apply to this RenderNode. Setting this to false will disable the auto-dark feature on everything this RenderNode draws, including any descendants. Setting this to true will allow this RenderNode to be automatically made dark, however a value of 'true' will not override any 'false' value in its parent chain nor will it prevent any 'false' in any of its children.

Parameters
allow Boolean: Whether or not to allow force dark.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setHasOverlappingRendering

Added in API level 29
fun setHasOverlappingRendering(hasOverlappingRendering: Boolean): Boolean

Sets whether the display list renders content which overlaps. Non-overlapping rendering can use a fast path for alpha that avoids rendering to an offscreen buffer. By default display lists consider they do not have overlapping content.

Parameters
hasOverlappingRendering Boolean: False if the content is guaranteed to be non-overlapping, true otherwise.

setOutline

Added in API level 29
fun setOutline(outline: Outline?): Boolean

Sets the outline, defining the shape that casts a shadow, and the path to be clipped if setClipToOutline is set. This will make a copy of the provided Outline, so any future modifications to the outline will need to call setOutline(android.graphics.Outline) with the modified outline for those changes to be applied.

Parameters
outline Outline?: The outline to use for this RenderNode. This value may be null.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setPivotX

Added in API level 29
fun setPivotX(pivotX: Float): Boolean

Sets the pivot value for the display list on the X axis

Parameters
pivotX Float: The pivot value of the display list on the X axis, in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setPivotY

Added in API level 29
fun setPivotY(pivotY: Float): Boolean

Sets the pivot value for the display list on the Y axis

Parameters
pivotY Float: The pivot value of the display list on the Y axis, in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setPosition

Added in API level 29
fun setPosition(position: Rect): Boolean

Sets the position of the RenderNode.

Parameters
position Rect: The position rectangle in pixels This value cannot be null.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setPosition

Added in API level 29
fun setPosition(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Boolean

Sets the position of the RenderNode.

Parameters
left Int: The left position of the RenderNode, in pixels
top Int: The top position of the RenderNode, in pixels
right Int: The right position of the RenderNode, in pixels
bottom Int: The bottom position of the RenderNode, in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setProjectBackwards

Added in API level 29
fun setProjectBackwards(shouldProject: Boolean): Boolean

Sets whether the RenderNode should be drawn immediately after the closest ancestor RenderNode containing a projection receiver.

The default is false, and the rendering of this node happens in the typical draw order.

If true, then at rendering time this rendernode will not be drawn in order with the Canvas.drawRenderNode(RenderNode) command that drew this RenderNode, but instead it will be re-positioned in the RenderNode tree to be drawn on the closet ancestor with a child rendernode that has setProjectionReceiver(boolean) as true.

The typical usage of this is to allow a child RenderNode to draw on a parent's background, such as the platform's usage with android.graphics.drawable.RippleDrawable. Consider the following structure, built out of which RenderNode called drawRenderNode on a different RenderNode:

+-------------+
         |RenderNode: P|
         +-+----------++
           |          |
           v          v
   +-------+-----+  +-+--------------+
   |RenderNode: C|  |RenderNode: P'BG|
   +-------+-----+  +----------------+
           |
           |
  +--------+-------+
  |RenderNode: C'BG|
  +----------------+
  
If P'BG is a projection receiver, and C'BG is set to project backwards then C'BG will behave as if it was drawn directly by P'BG instead of by C. This includes inheriting P'BG's clip instead of C's clip.
Parameters
shouldProject Boolean: true if the display list should be projected onto a containing volume. Default is false.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setProjectionReceiver

Added in API level 29
fun setProjectionReceiver(shouldReceive: Boolean): Boolean

Sets whether the RenderNode is a projection receiver. If true then this RenderNode's parent should draw any descendant RenderNodes with ProjectBackwards=true directly on top of it. Default value is false. See setProjectBackwards(boolean) for a description of what this entails.

Parameters
shouldReceive Boolean: True if this RenderNode is a projection receiver, false otherwise. Default is false.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setRenderEffect

Added in API level 31
fun setRenderEffect(renderEffect: RenderEffect?): Boolean

Configure the android.graphics.RenderEffect to apply to this RenderNode. This will apply a visual effect to the end result of the contents of this RenderNode before it is drawn into the destination. For example if RenderEffect.createBlurEffect(float, float, RenderEffect, Shader.TileMode) is provided, the contents will be drawn in a separate layer, then this layer will be blurred when this RenderNode is drawn into the destination.

Parameters
renderEffect RenderEffect?: to be applied to the RenderNode. Passing null clears all previously configured RenderEffects
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setRotationX

Added in API level 29
fun setRotationX(rotationX: Float): Boolean

Sets the rotation value for the display list around the X axis.

Parameters
rotationX Float: The rotation value of the display list, in degrees
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setRotationY

Added in API level 29
fun setRotationY(rotationY: Float): Boolean

Sets the rotation value for the display list around the Y axis.

Parameters
rotationY Float: The rotation value of the display list, in degrees
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setRotationZ

Added in API level 29
fun setRotationZ(rotation: Float): Boolean

Sets the rotation value for the display list around the Z axis.

Parameters
rotation Float: The rotation value of the display list, in degrees
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setScaleX

Added in API level 29
fun setScaleX(scaleX: Float): Boolean

Sets the scale value for the display list on the X axis.

Parameters
scaleX Float: The scale value of the display list
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setScaleY

Added in API level 29
fun setScaleY(scaleY: Float): Boolean

Sets the scale value for the display list on the Y axis.

Parameters
scaleY Float: The scale value of the display list
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setSpotShadowColor

Added in API level 29
fun setSpotShadowColor(color: Int): Boolean

Sets the color of the spot shadow that is drawn when the RenderNode has a positive Z or elevation value and is drawn inside of a Canvas.enableZ() section.

By default the shadow color is black. Generally, this color will be opaque so the intensity of the shadow is consistent between different RenderNodes with different colors.

The opacity of the final spot shadow is a function of the shadow caster height, the alpha channel of the outlineSpotShadowColor (typically opaque), and the android.R.attr#spotShadowAlpha theme attribute

Parameters
color Int: The color this RenderNode will cast for its elevation spot shadow.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setTranslationX

Added in API level 29
fun setTranslationX(translationX: Float): Boolean

Sets the translation value for the display list on the X axis.

Parameters
translationX Float: The X axis translation value of the display list, in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setTranslationY

Added in API level 29
fun setTranslationY(translationY: Float): Boolean

Sets the translation value for the display list on the Y axis.

Parameters
translationY Float: The Y axis translation value of the display list, in pixels
Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setTranslationZ

Added in API level 29
fun setTranslationZ(translationZ: Float): Boolean

Sets the translation value for the display list on the Z axis.

Return
Boolean True if the value changed, false if the new value was the same as the previous value.

setUseCompositingLayer

Added in API level 29
fun setUseCompositingLayer(
    forceToLayer: Boolean,
    paint: Paint?
): Boolean

Controls whether or not to force this RenderNode to render to an intermediate buffer. Internally RenderNode will already promote itself to a composition layer if it's useful for performance or required for the current combination of setAlpha(float) and setHasOverlappingRendering(boolean).

The usage of this is instead to allow for either overriding of the internal behavior if it's measured to be necessary for the particular rendering content in question or, more usefully, to add a composition effect to the RenderNode via the optional paint parameter.

Note: When a RenderNode is using a compositing layer it will also result in clipToBounds=true behavior.

Parameters
forceToLayer Boolean: if true this forces the RenderNode to use an intermediate buffer. Default & generally recommended value is false.
paint Paint?: The blend mode, alpha, and ColorFilter to apply to the compositing layer. Only applies if forceToLayer is true. The paint's alpha is multiplied with getAlpha() to resolve the final alpha of the RenderNode. If null then no additional composition effects are applied on top of the composition layer.
Return
Boolean True if the value changed, false if the new value was the same as the previous value.