Multitoque: desplazamiento lateral, zoom y rotación
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Para detectar gestos multitáctiles utilizados para el desplazamiento lateral, el zoom y la rotación, puedes usar el modificador transformable
, que no transforma los elementos por sí solo; únicamente detecta los gestos.
@Composable
private fun TransformableSample() {
// set up all transformation states
var scale by remember { mutableStateOf(1f) }
var rotation by remember { mutableStateOf(0f) }
var offset by remember { mutableStateOf(Offset.Zero) }
val state = rememberTransformableState { zoomChange, offsetChange, rotationChange ->
scale *= zoomChange
rotation += rotationChange
offset += offsetChange
}
Box(
Modifier
// apply other transformations like rotation and zoom
// on the pizza slice emoji
.graphicsLayer(
scaleX = scale,
scaleY = scale,
rotationZ = rotation,
translationX = offset.x,
translationY = offset.y
)
// add transformable to listen to multitouch transformation events
// after offset
.transformable(state = state)
.background(Color.Blue)
.fillMaxSize()
)
}
Si necesitas combinar el zoom, el desplazamiento lateral y la rotación con otros gestos, puedes usar el detector PointerInputScope.detectTransformGestures
.
Recomendaciones para ti
El contenido y las muestras de código que aparecen en esta página están sujetas a las licencias que se describen en la Licencia de Contenido. Java y OpenJDK son marcas registradas de Oracle o sus afiliados.
Última actualización: 2025-08-23 (UTC)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-23 (UTC)"],[],[],null,["# Multitouch: Panning, zooming, rotating\n\nTo detect multitouch gestures used for panning, zooming and rotating, you can\nuse the `transformable` modifier. This modifier does not transform elements by\nitself, it only detects the gestures.\n\n\n```kotlin\n@Composable\nprivate fun TransformableSample() {\n // set up all transformation states\n var scale by remember { mutableStateOf(1f) }\n var rotation by remember { mutableStateOf(0f) }\n var offset by remember { mutableStateOf(Offset.Zero) }\n val state = rememberTransformableState { zoomChange, offsetChange, rotationChange -\u003e\n scale *= zoomChange\n rotation += rotationChange\n offset += offsetChange\n }\n Box(\n Modifier\n // apply other transformations like rotation and zoom\n // on the pizza slice emoji\n .graphicsLayer(\n scaleX = scale,\n scaleY = scale,\n rotationZ = rotation,\n translationX = offset.x,\n translationY = offset.y\n )\n // add transformable to listen to multitouch transformation events\n // after offset\n .transformable(state = state)\n .background(Color.Blue)\n .fillMaxSize()\n )\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/touchinput/gestures/GesturesSnippets.kt#L324-L352\n```\n\n\u003cbr /\u003e\n\nIf you need to combine zooming, panning and rotation with other gestures, you\ncan use the\n[`PointerInputScope.detectTransformGestures`](/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.ui.input.pointer.PointerInputScope).detectTransformGestures(kotlin.Boolean,kotlin.Function4))\ndetector.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Understand gestures](/develop/ui/compose/touch-input/pointer-input/understand-gestures)"]]