Layout
Rive offers multiple options for controlling how graphics are laid out within the canvas, view, widget, or texture.
Responsive Layout
Rive’s new Layout feature lets you design resizable artboards with built-in responsive behavior, configured directly in the graphic. Just set a Fit of type Layout at runtime and the artboard will resize automatically. Optionally, provide a Layout Scale Factor to further adjust the scale of the content.
For more Editor information and how to configure your graphic see Layouts Overview.
The Alignment property will not have an effect when the using a Fit of type Layout.
Check the Feature Support page to see if this feature is already supported for your runtime.
Examples
Steps
- Set
Fit
toFit.Layout
- this will automatically scale and resize the artboard to match the canvas size when callingresizeDrawingSurfaceToCanvas()
. - Optionally set
layoutScaleFactor
for manual control of the artboard size (scale factor). - Subscribe to
window.onresize
and callresizeDrawingSurfaceToCanvas()
to adjust the artboard size as the canvas and window changes. - Subscribe to device pixel ratio changes and call
resizeDrawingSurfaceToCanvas()
to ensure the artboard updates correctly on various screen densities. For example, when dragging the window between multiple monitors with different device pixel ratios.
Examples
Steps
- Set
Fit
toFit.Layout
- this will automatically scale and resize the artboard to match the canvas size when callingresizeDrawingSurfaceToCanvas()
. - Optionally set
layoutScaleFactor
for manual control of the artboard size (scale factor). - Subscribe to
window.onresize
and callresizeDrawingSurfaceToCanvas()
to adjust the artboard size as the canvas and window changes. - Subscribe to device pixel ratio changes and call
resizeDrawingSurfaceToCanvas()
to ensure the artboard updates correctly on various screen densities. For example, when dragging the window between multiple monitors with different device pixel ratios.
Examples
Steps
- Set
fit
toFit.Layout
in theLayout
object - this will automatically scale and resize the artboard to match the canvas size. - Pass the
Layout
object to thelayout
prop inuseRive
. - Optionally set
layoutScaleFactor
in theLayout
object for manual control of the artboard’s scale factor. - The React runtime automatically handles window resizing and device pixel ratio changes.
Coming soon
Coming soon! This feature depends on an upcoming new Rive Flutter runtime—stay tuned for updates.
Examples
Steps
- Set
fit
on an instance ofRiveViewModel
tolayout
- Optionally set
layoutScaleFactor
onRiveViewModel
for manual control of an artboard’s scale factor.
To enable automatically determining the scale factor, set .layoutScaleFactor
to RiveViewModel.layoutScaleFactorAutomatic
. This is the default value; it is equivalent to -1
. When set, Rive will listen for window and screen changes for the view model’s view, and automatically apply the correct scale factor for the current view hierarchy.
Examples
See the Layout example.
Steps
- Set the XML
riveLayout
type to"LAYOUT"
:
- Alternatively, use a reference to the
RiveAnimationView
and set thefit
property toLAYOUT
:
- To adjust the scale factor of the contents, use the
layoutScaleFactor
property. This is nullable, so by default, it will use the density as reported byresources.displayMetrics.density
. You can override this to any positive float value, or return control to the system by resetting tonull
:
- Additionally, the artboard size can be controlled by using the
width
andheight
properties.resetArtboardSize()
can be used to return these values to their defaults:
Additional Layout Options
If the graphic doesn’t use Rive’s Layout feature, you can configure the layout with other Fit options and Alignment settings. See the sections below for more information on Fit and Alignment.
Use the Layout
object to configure Fit
and Alignment
. See Fit and Alignment below for all enum options.
Use the Layout
object to configure Fit
and Alignment
. See Fit and Alignment below for all enum options.
Use the Layout
object to configure Fit
and Alignment
. See Fit and Alignment below for all enum options.
With the useRive
hook:
Set layout attributes for Fit
and Alignment
on the Rive
component directly. See Fit and Alignment below for all enum options.
The current Rive Flutter runtime does not support Fit.Layout
. The next major release will support this which will be a breaking change.
The fit and alignment options behave like their counterparts in Flutter (see BoxFit
and Size
as examples).
Bounds options are absent; Flutter’s layout engine and options are the preferred way to handle positioning Rive content.
See values and descriptions in the sections below for Fit
and Alignment
. The runtime provides the following enums to set on layout parameters:
-
Fit
.fill
.contain
.cover
.fitWidth
.fitHeight
.scaleDown
.noFit
-
Alignment
.topLeft
.topCenter
.topRight
.centerLeft
.center
.centerRight
.bottomLeft
.bottomCenter
.bottomRight
SwiftUI
The following example shows how to set layout parameters and switch them at runtime:
UIKit
The following example shows how to set layout parameters and switch them at runtime:
The animation view can be further customized as part of specifying layout attributes.
riveFit
can be specified to determine how the animation should be resized to fit its container. The available choices are NONE
, FILL
, CONTAIN
, COVER
, FIT_WIDTH
, FIT_HEIGHT
, SCALE_DOWN
, and LAYOUT
.
riveAlignment
informs how it should be aligned within the container. The available choices are TOP_LEFT
, TOP_CENTER
, TOP_RIGHT
, CENTER_LEFT
, CENTER
, CENTER_RIGHT
, BOTTOM_LEFT
, BOTTOM_CENTER
, and BOTTOM_RIGHT
.
See more about these values and meanings in the sections below.
Specify the layout values in your Resource layout:
Or in your Activity code:
Fit
Fit determines how the Rive content will be fitted to the view. There are a number of options available:
Layout
: Rive content will be resized automatically based on layout constraints of the artboard to match the underlying view size. See the above for more information on how to use this option.Cover
: Rive will cover the view, preserving the aspect ratio. If the Rive content has a different ratio to the view, then the Rive content will be clipped.Contain
: (Default) Rive content will be contained within the view, preserving the aspect ratio. If the ratios differ, then a portion of the view will be unused.Fill
: Rive content will fill the available view. If the aspect ratios differ, then the Rive content will be stretched.FitWidth
: Rive content will fill to the width of the view. This may result in clipping or unfilled view space.FitHeight
: Rive content will fill to the height of the view. This may result in clipping or unfilled view space.None
: Rive content will render to the size of its artboard, which may result in clipping or unfilled view space.ScaleDown
: Rive content is scaled down to the size of the view, preserving the aspect ratio. This is equivalent toContain
when the content is larger than the canvas. If the canvas is larger, thenScaleDown
will not scale up.
Alignment
Alignment determines how the content aligns with respect to the view bounds. The following options are available:
Center
(Default)TopLeft
TopCenter
TopRight
CenterLeft
CenterRight
BottomLeft
BottomCenter
BottomRight
Bounds
The bounds for the area in which the Rive content will render can be set by providing the minimum and maximum x and y coordinates. These coordinates are relative to the view in which the Rive content is contained, and all must be provided. These will override alignment settings.
minX
minY
maxX
maxY
Was this page helpful?