<OnSwipe>
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Especifica a ação a ser realizada quando o usuário desliza o dedo sobre o layout. A velocidade
a sequência e o movimento da visualização segmentada são afetados pelo
velocidade e direção do gesto de deslizar, sujeito aos limites definidos com
parâmetros.
Pode haver vários nós <OnSwipe>
para um único <Transition>
, cada um
<OnSwipe>
especificando uma direção de deslizar e uma ação diferentes para
que serão realizadas quando o usuário deslizar a tela.
Sintaxe
<OnSwipe
motion:touchAnchorId="@id/target_view"
motion:touchAnchorSide="side"
[ motion:dragDirection="direction" ]
[ motion:dragScale="scale" ]
[ motion:maxVelocity="maxVelocity" ]
[ motion:maxAcceleration="maxAcceleration" ]
/>
Atributos
motion:touchAnchorId
- Visualização que está sendo movida com a ação de deslizar.
motion:touchAnchorSide
- Lado da visualização de destino em que o gesto de deslizar está ancorado.
MotionLayout
mantém um
distância constante entre a âncora e o dedo do usuário. Valores aceitáveis
são "left"
, "right"
, "top"
e "bottom"
.
motion:dragDirection
- Direção do movimento de deslizar do usuário. Se este atributo for definido, ele
O
<OnSwipe>
só se aplica a ações de deslizar na direção especificada. Valores aceitáveis
são "dragLeft"
, "dragRight"
, "dragUp"
e "dragDown"
.
motion:dragScale
Controla a distância que a visualização se move em relação ao comprimento da ação de deslizar. A
o valor padrão é 1, indicando que a visualização se move tanto quanto a ação de deslizar.
Se dragScale
for menor que 1, a visualização se moverá menos do que a distância de deslizar.
Por exemplo, um dragScale
de 0,5 significa que, se a ação de deslizar se mover 4 cm, a
a visualização do alvo se move 2 cm.
Se dragScale
for maior que 1, a visualização se moverá mais longe do que deslizar
distância. Por exemplo, um dragScale
de 1,5 significa que, se a ação de deslizar se mover 4
cm, a visualização de destino se moverá 6 cm.
motion:maxVelocity
Velocidade máxima da visualização de destino.
motion:maxAcceleration
Aceleração máxima da visualização de destino.
Contida em
O conteúdo e os exemplos de código nesta página estão sujeitos às licenças descritas na Licença de conteúdo. Java e OpenJDK são marcas registradas da Oracle e/ou suas afiliadas.
Última atualização 2025-07-27 UTC.
[null,null,["Última atualização 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)"]]