<OnWischen>
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Gibt die Aktion an, die ausgeführt werden soll, wenn der Nutzer über das Layout wischt. Die Geschwindigkeit der
werden die Bewegungsabläufe und die Bewegung der Zielansicht durch das
Geschwindigkeit und Wischrichtung abhängig von den Einschränkungen, die Sie in den optionalen
Parameter.
Es können mehrere <OnSwipe>
-Knoten für einen einzelnen <Transition>
mit jeweils
<OnSwipe>
gibt eine andere Wischrichtung und eine andere Aktion an,
wenn der Nutzer diese Wischbewegung ausführt.
Syntax
<OnSwipe
motion:touchAnchorId="@id/target_view"
motion:touchAnchorSide="side"
[ motion:dragDirection="direction" ]
[ motion:dragScale="scale" ]
[ motion:maxVelocity="maxVelocity" ]
[ motion:maxAcceleration="maxAcceleration" ]
/>
Attribute
motion:touchAnchorId
- Ansicht, die durch Wischen verschoben wird
motion:touchAnchorSide
- Seite der Zielansicht, auf der das Wischen verankert ist.
MotionLayout
behält Folgendes bei:
Abstand zwischen dem Anker und dem Finger der Nutzenden. Zulässige Werte
sind "left"
, "right"
, "top"
und "bottom"
.
motion:dragDirection
- Richtung der Wischbewegung des Nutzers. Wenn dieses Attribut festgelegt ist,
<OnSwipe>
gilt nur für Wischen in die angegebene Richtung. Zulässige Werte
sind "dragLeft"
, "dragRight"
, "dragUp"
und "dragDown"
.
motion:dragScale
Steuert die Distanz, die sich die Ansicht im Verhältnis zur Länge des Wischens bewegt. Die
Der Standardwert ist 1, was bedeutet, dass sich die Ansicht so weit bewegt wie beim Wischen.
Wenn dragScale
kleiner als 1 ist, wird die Ansicht weniger als die Wischstrecke verschoben.
Ein dragScale
von 0,5 bedeutet beispielsweise, dass sich das Wischen um 4 cm bewegt,
Die Zielansicht wird um 2 cm verschoben.
Wenn dragScale
größer als 1 ist, wird die Ansicht weiter verschoben als wischen.
Entfernung. Beispiel: Ein dragScale
von 1,5 bedeutet, dass sich beim Wischen 4
cm bewegt sich die Zielansicht um 6 cm.
motion:maxVelocity
Maximale Geschwindigkeit der Zielansicht.
motion:maxAcceleration
Maximale Beschleunigung der Zielansicht.
Enthalten in
Alle Inhalte und Codebeispiele auf dieser Seite unterliegen den Lizenzen wie im Abschnitt Inhaltslizenz beschrieben. Java und OpenJDK sind Marken oder eingetragene Marken von Oracle und/oder seinen Tochtergesellschaften.
Zuletzt aktualisiert: 2025-07-27 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)"]]