LayoutAspectRatio

data class LayoutAspectRatio : LayoutModifier
kotlin.Any
   ↳ androidx.ui.layout.LayoutAspectRatio

A layout modifier that attempts to size a layout to match a specified aspect ratio. The layout modifier will try to match one of the incoming constraints, in the following order: maxWidth, maxHeight, minWidth, minHeight. The size in the other dimension will then be computed according to the aspect ratio. Note that the provided aspectRatio will always correspond to the width/height ratio.

If a valid size that satisfies the constraints is found this way, the modifier will size the target layout to it: the layout will be measured with the tight constraints to match the size. If a child is present, it will be measured with tight constraints to match the size. If no valid size is found, the aspect ratio will not be satisfied, and the target layout will be measured with the original constraints.

Example usage:

import androidx.ui.foundation.Box
import androidx.ui.layout.aspectRatio
import androidx.ui.layout.preferredWidth

Box(Modifier.preferredWidth(100.dp).aspectRatio(2f), backgroundColor = Color.Green)

Summary

Public constructors

<init>(aspectRatio: Float)

A layout modifier that attempts to size a layout to match a specified aspect ratio.

Public methods

IntPx
Density.maxIntrinsicHeightOf(measurable: Measurable, width: IntPx, layoutDirection: LayoutDirection)

Determines the modified maximum intrinsic height of measurable.

IntPx
Density.maxIntrinsicWidthOf(measurable: Measurable, height: IntPx, layoutDirection: LayoutDirection)

Determines the modified maximum intrinsic width of measurable.

IntPx
Density.minIntrinsicHeightOf(measurable: Measurable, width: IntPx, layoutDirection: LayoutDirection)

Determines the modified minimum intrinsic height of measurable.

IntPx
Density.minIntrinsicWidthOf(measurable: Measurable, height: IntPx, layoutDirection: LayoutDirection)

Determines the modified minimum intrinsic width of measurable.

Constraints
Density.modifyConstraints(constraints: Constraints, layoutDirection: LayoutDirection)

Modifies constraints for performing measurement of the modified layout element.

Inherited functions

Inherited extension functions

From androidx.ui.layout
Modifier
Modifier.absolutePadding(left: Dp = 0.dp, top: Dp = 0.dp, right: Dp = 0.dp, bottom: Dp = 0.dp)

Apply additional space along each edge of the content in Dp: left, top, right and bottom.

Modifier

Attempts to size the content to match a specified aspect ratio by trying to match one of the incoming constraints in the following order: Constraints.maxWidth, Constraints.maxHeight, Constraints.minWidth, Constraints.minHeight.

Modifier

Have the content fill the Constraints.maxHeight of the incoming measurement constraints by setting the minimum height to be equal to the maximum height.

Modifier

Have the content fill the Constraints.maxWidth and Constraints.maxHeight of the incoming measurement constraints by setting the minimum width to be equal to the maximum width and the minimum height to be equal to the maximum height.

Modifier

Have the content fill the Constraints.maxWidth of the incoming measurement constraints by setting the minimum width to be equal to the maximum width.

Modifier
Modifier.height(height: Dp)

Declare the height of the content to be exactly heightdp.

Modifier
Modifier.heightIn(minHeight: Dp = Dp.Unspecified, maxHeight: Dp = Dp.Unspecified)

Constrain the height of the content to be between minHeightdp and maxHeightdp.

Modifier
Modifier.offset(x: Dp, y: Dp)

Offset the content by (xdp, ydp).

Modifier
Modifier.padding(start: Dp = 0.dp, top: Dp = 0.dp, end: Dp = 0.dp, bottom: Dp = 0.dp)

Apply additional space along each edge of the content in Dp: start, top, end and bottom.

Modifier

Apply alldp of additional space along each edge of the content, left, top, right and bottom.

Modifier

Declare the preferred height of the content to be the same as the min or max intrinsic height of the content.

Modifier

Declare the preferred height of the content to be exactly heightdp.

Modifier
Modifier.preferredHeightIn(minHeight: Dp = Dp.Unspecified, maxHeight: Dp = Dp.Unspecified)

Constrain the height of the content to be between minHeightdp and maxHeightdp as permitted by the incoming measurement Constraints.

Modifier

Declare the preferred size of the content to be exactly sizedp square.

Modifier
Modifier.preferredSize(width: Dp, height: Dp)

Declare the preferred size of the content to be exactly widthdp by heightdp.

Modifier
Modifier.preferredSizeIn(minWidth: Dp = Dp.Unspecified, minHeight: Dp = Dp.Unspecified, maxWidth: Dp = Dp.Unspecified, maxHeight: Dp = Dp.Unspecified)

Constrain the width of the content to be between minWidthdp and maxWidthdp and the height of the content to be between minHeight and maxHeight as permitted by the incoming measurement Constraints.

Modifier

Constrain the size of the content to be within constraints as permitted by the incoming measurement Constraints.

Modifier

Declare the preferred width of the content to be the same as the min or max intrinsic width of the content.

Modifier

Declare the preferred width of the content to be exactly widthdp.

Modifier
Modifier.preferredWidthIn(minWidth: Dp = Dp.Unspecified, maxWidth: Dp = Dp.Unspecified)

Constrain the width of the content to be between minWidthdp and maxWidthdp as permitted by the incoming measurement Constraints.

Modifier
Modifier.size(size: Dp)

Declare the size of the content to be exactly sizedp width and height.

Modifier
Modifier.size(width: Dp, height: Dp)

Declare the size of the content to be exactly widthdp and heightdp.

Modifier
Modifier.sizeIn(minWidth: Dp = Dp.Unspecified, minHeight: Dp = Dp.Unspecified, maxWidth: Dp = Dp.Unspecified, maxHeight: Dp = Dp.Unspecified)

Constrain the width of the content to be between minWidthdp and maxWidthdp, and the height of the content to be between minHeightdp and maxHeightdp.

Modifier

Constrain the size of the content to be within constraints.

Modifier
Modifier.width(width: Dp)

Declare the width of the content to be exactly widthdp.

Modifier
Modifier.widthIn(minWidth: Dp = Dp.Unspecified, maxWidth: Dp = Dp.Unspecified)

Constrain the width of the content to be between minWidthdp and maxWidthdp.

Modifier
Modifier.wrapContentHeight(align: Alignment = Alignment.Center)

Allow the content to measure at its desired height without regard for the incoming measurement minimum height constraint.

Modifier
Modifier.wrapContentHeight(align: Alignment.Vertical = Alignment.CenterVertically)

Allow the content to measure at its desired height without regard for the incoming measurement minimum height constraint.

Modifier
Modifier.wrapContentSize(align: Alignment = Alignment.Center)

Allow the content to measure at its desired size without regard for the incoming measurement minimum width or minimum height constraints.

Modifier
Modifier.wrapContentWidth(align: Alignment = Alignment.Center)

Allow the content to measure at its desired width without regard for the incoming measurement minimum width constraint.

Modifier
Modifier.wrapContentWidth(align: Alignment.Horizontal = Alignment.CenterHorizontally)

Allow the content to measure at its desired width without regard for the incoming measurement minimum width constraint.

From androidx.ui.core
Modifier

Clip the content to shape.

Modifier

Clip the content to the bounds of a layer defined at this modifier.

Modifier
Modifier.drawBehind(onDraw: DrawScope.() -> Unit)

Draw into a Canvas behind the modified content.

Modifier
Modifier.drawLayer(scaleX: Float = 1f, scaleY: Float = 1f, alpha: Float = 1f, translationX: Float = 0f, translationY: Float = 0f, shadowElevation: Float = 0f, rotationX: Float = 0f, rotationY: Float = 0f, rotationZ: Float = 0f, transformOrigin: TransformOrigin = TransformOrigin.Center, outlineShape: Shape? = null, clipToBounds: Boolean = false, clipToOutline: Boolean = false)

Draw the content into a layer.

Modifier

Draw content with modified opacity (alpha) that may be less than 1.

Modifier
Modifier.drawShadow(elevation: Dp, shape: Shape = RectangleShape, clipToOutline: Boolean = elevation > 0.dp, opacity: Float = 1f)

Creates a DrawLayerModifier that draws the shadow.

Modifier

Creates a DrawModifier that allows the developer to draw before or after the layout's contents.

Modifier
Modifier.onChildPositioned(onChildPositioned: (LayoutCoordinates) -> Unit)

Invoke onChildPositioned with the LayoutCoordinates of each child element after each one is positioned.

Modifier

Invoke onPositioned with the LayoutCoordinates of the element after positioning.

Modifier
Modifier.paint(painter: Painter, sizeToIntrinsics: Boolean = true, alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Inside, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, rtl: Boolean = false)

Paint the content using painter.

Modifier

Tag the element with tag to identify the element within its parent.

Modifier

Creates a ZIndexModifier that controls the drawing order for the children of the same layout parent.

From androidx.ui.core.gesture
Modifier

Responds to pointers going down and up (tap) and then down and up again (another tap) with minimal gap of time between the first up and the second down.

Modifier
Modifier.dragGestureFilter(dragObserver: DragObserver, canDrag: (Direction) -> Boolean = null, startDragImmediately: Boolean = false)

This gesture detector detects dragging in any direction.

Modifier

This gesture detector detects dragging in any direction, but only after a long press has first occurred.

Modifier

Responds to a pointer being "down" for an extended amount of time.

Modifier
Modifier.pressIndicatorGestureFilter(onStart: (PxPosition) -> Unit = null, onStop: () -> Unit = null, onCancel: () -> Unit = null, enabled: Boolean = true)

This gesture detector has callbacks for when a press gesture starts and ends for the purposes of displaying visual feedback for those two states.

Modifier
Modifier.rawDragGestureFilter(dragObserver: DragObserver, canStartDragging: () -> Boolean = null)

This gesture detector detects dragging in any direction.

Modifier
Modifier.rawPressStartGestureFilter(onPressStart: (PxPosition) -> Unit, enabled: Boolean = false, executionPass: PointerEventPass = PointerEventPass.PostUp)

Reacts if the first pointer input change it sees is an unconsumed down change, and if it reacts, consumes all further down changes.

Modifier
Modifier.rawScaleGestureFilter(scaleObserver: RawScaleObserver, canStartScaling: () -> Boolean = null)

This gesture detector detects scaling.

Modifier

This gesture detector detects scaling.

Modifier
Modifier.scaleSlopExceededGestureFilter(onScaleSlopExceeded: () -> Unit)

This gesture detector detects when a user's pointer input is intended to include scaling.

Modifier
Modifier.tapGestureFilter(onTap: () -> Unit)

This gesture detector fires a callback when a traditional press is being released.

Modifier
Modifier.touchSlopExceededGestureFilter(onTouchSlopExceeded: () -> Unit, canDrag: (Direction) -> Boolean = null)

This gesture filter detects when at least one pointer has moved far enough to exceed touch slop.

From androidx.ui.foundation.gestures
Modifier
Modifier.draggable(dragDirection: DragDirection, onDragStarted: (startedPosition: PxPosition) -> Unit = {}, onDragStopped: (velocity: Float) -> Unit = {}, enabled: Boolean = true, interactionState: InteractionState? = null, startDragImmediately: Boolean = false, onDragDeltaConsumptionRequested: (Float) -> Float)

Configure touch dragging for the UI element in a single DragDirection.

Modifier
Modifier.scrollable(dragDirection: DragDirection, scrollableState: ScrollableState, onScrollStarted: (startedPosition: PxPosition) -> Unit = {}, onScrollStopped: (velocity: Float) -> Unit = {}, enabled: Boolean = true)

Enable scrolling and flinging of the modified UI element.

From androidx.ui.foundation
Modifier

Draws shape with paint behind the content.

Modifier
Modifier.drawBackground(color: Color, shape: Shape = RectangleShape)

Draws shape with a solid color behind the content.

Modifier
Modifier.drawBackground(brush: Brush, shape: Shape = RectangleShape)

Draws shape with brush behind the content.

Modifier
Modifier.drawBorder(border: Border, shape: Shape = RectangleShape)

Returns a Modifier that adds border with appearance specified with a border and a shape

Modifier
Modifier.drawBorder(size: Dp, color: Color, shape: Shape = RectangleShape)

Returns a Modifier that adds border with appearance specified with size, color and a shape

Modifier
Modifier.drawBorder(size: Dp, brush: Brush, shape: Shape)

Returns a Modifier that adds border with appearance specified with size, brush and a shape

From androidx.ui.graphics.vector
Modifier
Modifier.drawVector(defaultWidth: Px, defaultHeight: Px, viewportWidth: Float = defaultWidth.value, viewportHeight: Float = defaultHeight.value, tintColor: Color = DefaultTintColor, tintBlendMode: BlendMode = DefaultTintBlendMode, alignment: Alignment = DefaultAlignment, contentScale: ContentScale = ContentScale.Inside, name: String = "", children: VectorScope.(viewportWidth: Float, viewportHeight: Float) -> Unit)

Modifier to draw a vector graphic with the provided width, height and viewport dimensions

From androidx.ui.material.ripple
Modifier
Modifier.ripple(bounded: Boolean = true, radius: Dp? = null, color: Color = Color.Unset, enabled: Boolean = true, clock: AnimationClockObservable = AnimationClockAmbient.current)

Ripple is a Modifier which draws the visual indicator for a pressed state.

From androidx.ui.core.semantics
SemanticsModifier
Modifier.semanticsCore(container: Boolean = false, mergeAllDescendants: Boolean = false, properties: SemanticsPropertyReceiver.() -> Unit = null)

Properties

Float

A positive non-zero value representing the aspect ratio.

Inherited extension properties

From androidx.ui.layout
Modifier

Modifier that changes the LayoutDirection of the wrapped layout to LayoutDirection.Ltr.

Modifier

Modifier that changes the LayoutDirection of the wrapped layout to LayoutDirection.Rtl.

Public constructors

<init>

LayoutAspectRatio(aspectRatio: Float)

A layout modifier that attempts to size a layout to match a specified aspect ratio. The layout modifier will try to match one of the incoming constraints, in the following order: maxWidth, maxHeight, minWidth, minHeight. The size in the other dimension will then be computed according to the aspect ratio. Note that the provided aspectRatio will always correspond to the width/height ratio.

If a valid size that satisfies the constraints is found this way, the modifier will size the target layout to it: the layout will be measured with the tight constraints to match the size. If a child is present, it will be measured with tight constraints to match the size. If no valid size is found, the aspect ratio will not be satisfied, and the target layout will be measured with the original constraints.

Example usage:

import androidx.ui.foundation.Box
import androidx.ui.layout.aspectRatio
import androidx.ui.layout.preferredWidth

Box(Modifier.preferredWidth(100.dp).aspectRatio(2f), backgroundColor = Color.Green)
Parameters
aspectRatio: Float A positive non-zero value representing the aspect ratio.

Public methods

maxIntrinsicHeightOf

fun Density.maxIntrinsicHeightOf(
    measurable: Measurable,
    width: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified maximum intrinsic height of measurable. See Measurable.maxIntrinsicHeight.

maxIntrinsicWidthOf

fun Density.maxIntrinsicWidthOf(
    measurable: Measurable,
    height: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified maximum intrinsic width of measurable. See Measurable.maxIntrinsicWidth.

minIntrinsicHeightOf

fun Density.minIntrinsicHeightOf(
    measurable: Measurable,
    width: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified minimum intrinsic height of measurable. See Measurable.minIntrinsicHeight.

minIntrinsicWidthOf

fun Density.minIntrinsicWidthOf(
    measurable: Measurable,
    height: IntPx,
    layoutDirection: LayoutDirection
): IntPx

Determines the modified minimum intrinsic width of measurable. See Measurable.minIntrinsicWidth.

modifyConstraints

fun Density.modifyConstraints(
    constraints: Constraints,
    layoutDirection: LayoutDirection
): Constraints

Modifies constraints for performing measurement of the modified layout element.

Properties

aspectRatio

val aspectRatio: Float

A positive non-zero value representing the aspect ratio.