<KeyPosition>
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
指定视图在运动序列中特定时刻的位置。
该属性用于调整默认的运动路径。
例如,如果某个对象从左上角开始,并以
默认运动序列会沿对角线向下移动对象
屏幕上。通过添加一个或多个 <KeyPosition>
元素,您可以使
路径。
语法
<KeyPosition
motion:motionTarget="@id/targetPath"
motion:framePosition="percentage"
motion:keyPositionType="type"
motion:percentX="xOffset"
motion:percentY="yOffset"
/>
属性
motion:motionTarget
- 其运动由此
<KeyPosition>
控制的视图。
motion:framePosition
- 1 到 99 之间的整数,用于指定视图在运动序列中的什么时间点到达
由此
<KeyPosition>
指定的点。例如,如果
framePosition
为 25,则视图到达指定点
四分之一的时间长度
motion:percentX
、motion:percentY
- 指定视图到达的位置。
keyPositionType
属性指定如何解释这些值。
motion:keyPositionType
- 指定
percentX
和 percentY
值的显示方式
。可能的设置如下 :
<ph type="x-smartling-placeholder"></ph>
<ph type="x-smartling-placeholder"></ph>
parentRelative
percentX
和 percentY
是相对于
父级视图X 是横轴,范围为 0,左侧为 0
1 表示右侧。Y 为纵轴,其中 0 为
1 表示底部,1 表示底部。
例如,如果您希望目标视图到达
父视图右侧,将 percentX
设置为 1,
将 percentY
更改为 0.5。
deltaRelative
percentX
和 percentY
是相对于
视图在整个运动序列过程中移动的距离。
X 为横轴,Y 为纵轴。在
0 表示视图在该轴上的起始位置,1 表示视图在
排名。
假设目标视图向上移动 100dp,向右移动 100dp,但是您希望
在前四分之一动作中向下移动 40 dp,然后向后弧形移动
。将 framePosition
设置为 25,将 keyPositionType
设置为
deltaRelative
,将 percentY
设置为 -0.4。
pathRelative
X 轴是目标视图在
其中 0 为起始位置,1 为最终位置。通过
Y 轴垂直于 X 轴,
添加右侧“路径”和“负”值。因此,视图的初始位置是
(0,0)
,最终位置为 (1,0)
。设置
非零 percentY
会导致视图向一个方向弧形或
其他。
假设您希望视图占据运动序列的一半,
然后加速覆盖其余的 90%设置
framePosition
至 50,keyPositionType
至
pathRelative
,从 percentX
更新为 0.1。
percentY
仍为 0。
包含于
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# <KeyPosition>\n\nSpecifies a view's position at a specific moment during the motion sequence.\nThis attribute is used to adjust the default path of the motion.\n\nFor example, if an object begins at the upper-left corner and ends at the\nlower-right corner, the default motion sequence moves the object diagonally down\nthe screen. By adding one or more `\u003cKeyPosition\u003e` elements, you can deform the\npath.\n\nSyntax\n------\n\n```xml\n\u003cKeyPosition\n motion:motionTarget=\"@id/targetPath\"\n motion:framePosition=\"percentage\"\n motion:keyPositionType=\"type\"\n motion:percentX=\"xOffset\"\n motion:percentY=\"yOffset\"\n/\u003e\n```\n\nAttributes\n----------\n\n`motion:motionTarget`\n: View whose motion is controlled by this `\u003cKeyPosition\u003e`.\n\n`motion:framePosition`\n: Integer from 1 to 99 specifying when in the motion sequence the view reaches\n the point specified by this `\u003cKeyPosition\u003e`. For example, if\n `framePosition` is 25, the view reaches the specified point\n one-quarter of the way through the motion.\n\n`motion:percentX`, `motion:percentY`\n: Specify the position the view reaches. The `keyPositionType`\n attribute specifies how these values are interpreted.\n\n`motion:keyPositionType`\n: Specifies how the `percentX` and `percentY` values are\n interpreted. Possible settings are the following:\n\nContained In\n------------\n\n- [`\u003cKeyFrameSet\u003e`](/training/constraint-layout/motionlayout/ref/keyframeset)"]]