# MovableComponent

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/MovableComponent.kt+class:androidx.xr.scenecore.MovableComponent) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
public final class MovableComponent extends Component
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.MovableComponent](https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent) |

*** ** * ** ***

This `https://developer.android.com/reference/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

Creating this Component with `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createCustomMovable(androidx.xr.runtime.Session,kotlin.Boolean,java.util.concurrent.Executor,androidx.xr.scenecore.EntityMoveListener)` will create the Component but not move the attached Entity. It requires an `https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener` which will provide suggested Poses from the system that an application can use to move the attached Entity. This should be used if the application wants to add custom logic for the Entity's movement. `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createSystemMovable(androidx.xr.runtime.Session,kotlin.Boolean)` will create the Component and move the attached Entity when the user drags it to a position recommended by the system. `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createAnchorable(androidx.xr.runtime.Session,kotlin.collections.Set,kotlin.Boolean)` will create the Component, move the attached Entity when the user drags it, and also potentially reparent the Entity to a new `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace`. This will occur if the user lets go of the Entity near a perception plane that matches the settings in the provided `https://developer.android.com/reference/androidx/xr/scenecore/AnchorPlacement`.

This component cannot be attached to an `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` or to the `https://developer.android.com/reference/androidx/xr/scenecore/ActivitySpace`. Calling `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

## Summary

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#addMoveListener(androidx.xr.scenecore.EntityMoveListener)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener)` Adds a listener to the set of active listeners for the move events. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#addMoveListener(java.util.concurrent.Executor,androidx.xr.scenecore.EntityMoveListener)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener )` Adds a listener to the set of active listeners for the move events. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createAnchorable(androidx.xr.runtime.Session,kotlin.collections.Set,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorPlacement> anchorPlacement, boolean disposeParentOnReAnchor )` Public factory function for creating a MovableComponent. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createCustomMovable(androidx.xr.runtime.Session,kotlin.Boolean,java.util.concurrent.Executor,androidx.xr.scenecore.EntityMoveListener)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, boolean scaleInZ, https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener )` Public factory function for creating a MovableComponent. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createSystemMovable(androidx.xr.runtime.Session,kotlin.Boolean)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, boolean scaleInZ)` Public factory function for creating a MovableComponent. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/FloatSize3d` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#getSize()()` The size of the move affordance in local space virtual meters. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#removeMoveListener(androidx.xr.scenecore.EntityMoveListener)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener)` Removes a listener from the set of active listeners for the move events. |
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#setSize(androidx.xr.runtime.math.FloatSize3d)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/FloatSize3d value)` The size of the move affordance in local space virtual meters. |

| ### Protected methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#onAttach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Called by the framework when this component is being added to an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#onDetach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Called by the framework when this component is being removed from an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |

## Public methods

### addMoveListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final void addMoveListener(@NonNull EntityMoveListener entityMoveListener)
```

Adds a listener to the set of active listeners for the move events. The listener will be invoked regardless of whether the `https://developer.android.com/reference/androidx/xr/scenecore/Entity` is being moved by the system or the user.

The listener is invoked on the main thread.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener` | The move event listener to set. |

### addMoveListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final void addMoveListener(
    @NonNull Executor executor,
    @NonNull EntityMoveListener entityMoveListener
)
```

Adds a listener to the set of active listeners for the move events. The listener will be invoked regardless of whether the `https://developer.android.com/reference/androidx/xr/scenecore/Entity` is being moved by the system or the user.

The listener is invoked on the provided `https://developer.android.com/reference/java/util/concurrent/Executor.html`. If the app intends to modify the UI elements/views during the callback, the app should provide the thread executor that is appropriate for the UI operations. For example, if the app is using the main thread to render the UI, the app should provide the main thread (Looper.getMainLooper()) executor. If the app is using a separate thread to render the UI, the app should provide the executor for that thread.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The executor to run the listener on. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener` | The move event listener to set. |

### createAnchorable

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public static final @NonNull MovableComponent createAnchorable(
    @NonNull Session session,
    @NonNull Set<@NonNull AnchorPlacement> anchorPlacement,
    boolean disposeParentOnReAnchor
)
```

Public factory function for creating a MovableComponent.

This `https://developer.android.com/reference/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will move and potentially Anchor the Entity. When anchored a new `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` will be created and set as the parent of the Entity. If the entity is moved off of a created `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` it will be reparented to the `https://developer.android.com/reference/androidx/xr/scenecore/ActivitySpace`. An `https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener` can be attached to receive callbacks when the Entity is being moved and to see if it was reparented to an AnchorSpace.

This component cannot be attached to an AnchorSpace or to the ActivitySpace. Calling `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

This functionality requires `https://developer.android.com/reference/androidx/xr/runtime/Session` to be called with `https://developer.android.com/reference/androidx/xr/runtime/PlaneTrackingMode#HORIZONTAL_AND_VERTICAL()`. This configuration requires that the `SCENE_UNDERSTANDING_COARSE` Android permission is granted. If not granted, the `anchorable` functionality will be disabled, and the element will behave as if the anchoring functionality was not applied.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The `https://developer.android.com/reference/androidx/xr/runtime/Session` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/AnchorPlacement> anchorPlacement` | A Set containing different `https://developer.android.com/reference/androidx/xr/scenecore/AnchorPlacement` for how to anchor the Entity with a MovableComponent. When empty this Entity will not be anchored. |
| `boolean disposeParentOnReAnchor` | A Boolean, which if set to true, when an Entity is moved off of an `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` that was created by the underlying MovableComponent, and the AnchorSpace has no other children, the AnchorSpace will be disposed, and the underlying Anchor will be detached. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent` | MovableComponent instance. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if created with an Empty Set of for anchorPlacement |

### createCustomMovable

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public static final @NonNull MovableComponent createCustomMovable(
    @NonNull Session session,
    boolean scaleInZ,
    Executor executor,
    @NonNull EntityMoveListener entityMoveListener
)
```

Public factory function for creating a MovableComponent.

This `https://developer.android.com/reference/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will not move or rescale the Entity, but it could be done using the `https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener#onMoveUpdate(androidx.xr.scenecore.Entity,androidx.xr.runtime.math.Ray,androidx.xr.runtime.math.Pose,kotlin.Float)` callback.

This component cannot be attached to an `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` or to the `https://developer.android.com/reference/androidx/xr/scenecore/ActivitySpace`. Calling `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The `https://developer.android.com/reference/androidx/xr/runtime/Session` instance. |
| `boolean scaleInZ` | A Boolean which tells the system to update the scale of the Entity as the user moves it closer and further away. This is mostly useful for Panel auto-rescaling with distance. |
| `https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The executor to run the listener on. If set to null, the listener will be invoked on the main thread. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener` | A move event listener for the event. The application should set the entity position and scale as desired using `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)` and `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setScale(kotlin.Float,androidx.xr.scenecore.Space)` in the `https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener#onMoveUpdate(androidx.xr.scenecore.Entity,androidx.xr.runtime.math.Ray,androidx.xr.runtime.math.Pose,kotlin.Float)` callback. To have the system do this movement use `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createSystemMovable(androidx.xr.runtime.Session,kotlin.Boolean)` or `https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent#createAnchorable(androidx.xr.runtime.Session,kotlin.collections.Set,kotlin.Boolean)`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent` | MovableComponent instance. |

### createSystemMovable

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public static final @NonNull MovableComponent createSystemMovable(@NonNull Session session, boolean scaleInZ)
```

Public factory function for creating a MovableComponent.

This `https://developer.android.com/reference/androidx/xr/scenecore/Component` can be attached to a single instance of an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. When attached, this Component will enable the user to translate the Entity by pointing and dragging on it.

When created with this function the MovableComponent will move and rescale the Entity. `https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener` can be attached to received callbacks when the Entity is being moved.

This component cannot be attached to an `https://developer.android.com/reference/androidx/xr/scenecore/AnchorSpace` or to the `https://developer.android.com/reference/androidx/xr/scenecore/ActivitySpace`. Calling `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` to an Entity with these types will return false.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The `https://developer.android.com/reference/androidx/xr/runtime/Session` instance. |
| `boolean scaleInZ` | A Boolean which tells the system to update the scale of the Entity as the user moves it closer and further away. This is mostly useful for Panel auto-rescaling with distance. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MovableComponent` | MovableComponent instance. |

### getSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final @NonNull FloatSize3d getSize()
```

The size of the move affordance in local space virtual meters. This property determines the size of the bounding box that is used to draw the draggable move affordances around the `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. This property can be modified if the move affordance needs to be larger or smaller than the Entity itself.

When attaching this component to an entity, the apps may update this value to appropriate new value, such as the size of the entity this component is being added to. If apps don't set this value, the component will try to use the entity's dimensions as value for this property where applicable, or default to (1 x 1 x 1).

### removeMoveListener

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final void removeMoveListener(@NonNull EntityMoveListener entityMoveListener)
```

Removes a listener from the set of active listeners for the move events.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/EntityMoveListener entityMoveListener` | The move event listener to remove. |

### setSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final void setSize(@NonNull FloatSize3d value)
```

The size of the move affordance in local space virtual meters. This property determines the size of the bounding box that is used to draw the draggable move affordances around the `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. This property can be modified if the move affordance needs to be larger or smaller than the Entity itself.

When attaching this component to an entity, the apps may update this value to appropriate new value, such as the size of the entity this component is being added to. If apps don't set this value, the component will try to use the entity's dimensions as value for this property where applicable, or default to (1 x 1 x 1).

## Protected methods

### onAttach

```
protected boolean onAttach(@NonNull Entity entity)
```

Called by the framework when this component is being added to an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided `https://developer.android.com/reference/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity` | The `https://developer.android.com/reference/androidx/xr/scenecore/Entity` to which this component is being attached. |

| Returns |
|---|---|
| `boolean` | `true` if the component was successfully attached; `false` if the `https://developer.android.com/reference/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)` does not support this component or if attachment failed. |

### onDetach

```
protected void onDetach(@NonNull Entity entity)
```

Called by the framework when this component is being removed from an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`.

This method is triggered when `https://developer.android.com/reference/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)` is invoked. Implementations should override this method to release resources or undo any changes made during `https://developer.android.com/reference/androidx/xr/scenecore/Component#onAttach(androidx.xr.scenecore.Entity)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity` | The `https://developer.android.com/reference/androidx/xr/scenecore/Entity` from which this component is being detached. |