<Al deslizar>
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Especifica la acción que se debe realizar cuando el usuario desliza el dedo sobre el diseño. La velocidad de
la secuencia de movimiento y el movimiento de la vista objetivo se ven afectados por
la velocidad y la dirección del deslizamiento, sujeto a los límites que establezcas con
parámetros.
Puede haber varios nodos <OnSwipe>
para una sola <Transition>
, y cada
<OnSwipe>
especifica una dirección de deslizamiento diferente y una acción distinta para
cuando el usuario hace ese deslizamiento.
Sintaxis
<OnSwipe
motion:touchAnchorId="@id/target_view"
motion:touchAnchorSide="side"
[ motion:dragDirection="direction" ]
[ motion:dragScale="scale" ]
[ motion:maxVelocity="maxVelocity" ]
[ motion:maxAcceleration="maxAcceleration" ]
/>
Atributos
motion:touchAnchorId
- Vista que se mueve cuando se desliza el dedo.
motion:touchAnchorSide
- Lado de la vista de destino al que está anclado el deslizamiento.
MotionLayout
conserva un
y debe haber una distancia constante entre el ancla y el dedo del usuario. Valores aceptables
son "left"
, "right"
, "top"
y "bottom"
.
motion:dragDirection
- Dirección del deslizamiento del usuario. Si se establece este atributo, este
<OnSwipe>
solo se aplica a deslizamientos en la dirección especificada. Valores aceptables
son "dragLeft"
, "dragRight"
, "dragUp"
y "dragDown"
.
motion:dragScale
Controla la distancia que recorre la vista en relación con la duración del deslizamiento. El
el valor predeterminado es 1, lo que indica que la vista se mueve tanto como el deslizamiento.
Si dragScale
es menor que 1, la vista se mueve menos que la distancia de deslizamiento.
Por ejemplo, un dragScale
de 0.5 significa que, si el deslizamiento se mueve 4 cm, la
la vista objetivo se mueve 2 cm.
Si dragScale
es mayor que 1, la vista se mueve más lejos que el gesto de deslizar
distancia. Por ejemplo, un dragScale
de 1.5 significa que, si el deslizamiento se mueve a 4
cm, la vista objetivo se mueve 6 cm.
motion:maxVelocity
Es la velocidad máxima de la vista de destino.
motion:maxAcceleration
Aceleración máxima de la vista de destino.
Dónde se incluye
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-07-27 (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-07-27 (UTC)"],[],[],null,["# <OnSwipe>\n\nSpecifies the action to perform when the user swipes on the layout. The speed of\nthe motion sequence and the motion of the targeted view are affected by the\nspeed and direction of the swipe, subject to the limits you set with optional\nparameters.\n\nThere can be multiple `\u003cOnSwipe\u003e` nodes for a single `\u003cTransition\u003e`, with each\n`\u003cOnSwipe\u003e` specifying a different swipe direction and a different action to\nperform when the user performs that swipe.\n\nSyntax\n------\n\n```xml\n\u003cOnSwipe\n motion:touchAnchorId=\"@id/target_view\"\n motion:touchAnchorSide=\"side\"\n[ motion:dragDirection=\"direction\" ]\n[ motion:dragScale=\"scale\" ]\n[ motion:maxVelocity=\"maxVelocity\" ]\n[ motion:maxAcceleration=\"maxAcceleration\" ]\n /\u003e\n```\n\nAttributes\n----------\n\n`motion:touchAnchorId`\n: View that is being moved by the swipe.\n\n`motion:touchAnchorSide`\n: Side of the target view that the swipe is anchored to. `MotionLayout` keeps a\n constant distance between the anchor and the user's finger. Acceptable values\n are `\"left\"`, `\"right\"`, `\"top\"`, and `\"bottom\"`.\n\n`motion:dragDirection`\n: Direction of the user's swipe motion. If this attribute is set, this\n `\u003cOnSwipe\u003e` only applies to swipes in the specified direction. Acceptable values\n are `\"dragLeft\"`, `\"dragRight\"`, `\"dragUp\"`, and `\"dragDown\"`.\n\n`motion:dragScale`\n\n: Controls the distance the view moves relative to the length of the swipe. The\n default value is 1, indicating that the view moves as far as the swipe does.\n If `dragScale` is less than 1, the view moves less than the swipe distance.\n For example, a `dragScale` of 0.5 means that if the swipe moves 4 cm, the\n target view moves 2 cm.\n\n If `dragScale` is greater than 1, the view moves farther than the swipe\n distance. For example, a `dragScale` of 1.5 means that if the swipe moves 4\n cm, the target view moves 6 cm.\n\n`motion:maxVelocity`\n\n: Maximum velocity of the target view.\n\n`motion:maxAcceleration`\n\n: Maximum acceleration of the target view.\n\nContained in\n------------\n\n- [`\u003cTransition\u003e`](/training/constraint-layout/motionlayout/ref/transition)"]]