<KeyFrameSet>
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Chỉ định vị trí và thuộc tính cho các chế độ xem trong suốt quá trình chuyển động
trình tự. Theo mặc định, chuyển động tiếp tục từ trạng thái ban đầu đến trạng thái kết thúc.
Bạn có thể tạo các chuyển động phức tạp hơn bằng <KeyFrameSet>
.
<KeyFrameSet>
chứa
<KeyPosition>
hoặc
<KeyAttribute>
nút. Các nút này xác định vị trí hoặc thuộc tính của khung hiển thị mục tiêu tại
điểm cụ thể trong chuyển động.
MotionLayout
tạo ảnh động mượt mà khung cảnh từ điểm xuất phát đến mỗi điểm trung gian
và sau đó tới đích đến cuối cùng.
Giả sử trạng thái ban đầu của chuỗi chuyển động có một quả bóng mờ trong
góc dưới bên trái của chế độ xem và trạng thái cuối cùng làm cho quả bóng trong suốt
góc trên bên phải. Theo mặc định, MotionLayout
sẽ di chuyển bóng mượt mà
theo đường chéo, dần dần trở nên trong suốt cho đến khi mất đi khi
tới điểm đến. Bằng cách sử dụng <KeyFrameSet>
, bạn có thể thay đổi hành vi này.
Ví dụ: bạn có thể làm cho quả bóng di chuyển theo chiều dọc vào góc trên bên trái
trong khi vẫn hoàn toàn mờ đục, sau đó di chuyển theo chiều ngang sang phía trên bên phải
góc trong khi mờ dần. Bạn có thể thực hiện việc này bằng cách tạo một <KeyFrameSet>
và
thêm <KeyPosition>
và <KeyAttribute>
bên trong đó. <KeyPosition>
xác định vị trí trung gian của quả bóng và <KeyAttribute>
chỉ định rằng quả bóng vẫn mờ ở điểm giữa chuyển động.
Cú pháp
<KeyFrameSet>
[ <KeyPosition/>... ]
[ <KeyAttribute/>...]
</KeyFrameSet>
Có trong:
<Transition>
Chứa
<KeyPosition>
- Chỉ định vị trí của khung hiển thị tại một thời điểm cụ thể trong trình tự chuyển động.
<KeyAttribute>
- Chỉ định các thuộc tính của thành phần hiển thị tại một thời điểm cụ thể trong trình tự chuyển động.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# <KeyFrameSet>\n\nSpecifies location and attributes for views over the course of the motion\nsequence. By default, motion proceeds from the initial state to the end state.\nBy using `\u003cKeyFrameSet\u003e`, you can build more complex motions.\n\nThe `\u003cKeyFrameSet\u003e` contains\n[`\u003cKeyPosition\u003e`](/training/constraint-layout/motionlayout/ref/keyposition) or\n[`\u003cKeyAttribute\u003e`](/training/constraint-layout/motionlayout/ref/keyattribute)\nnodes. These nodes specify the position or attributes of a target view at a\nspecific point in the motion.\n[`MotionLayout`](/reference/androidx/constraintlayout/motion/widget/MotionLayout)\nsmoothly animates the view from the starting point to each intermediate point\nand then to the final destination.\n\nSuppose the initial state of the motion sequence has an opaque ball in the\nlower-left corner of the view, and the final state makes the ball transparent in\nthe upper-right corner. By default, the `MotionLayout` moves the ball smoothly\nin a diagonal line, gradually becoming transparent until it vanishes when it\nreaches its destination. By using `\u003cKeyFrameSet\u003e`, you can change this behavior.\nFor example, you can make the ball move vertically to the upper-left corner\nwhile remaining entirely opaque, then move horizontally to the upper-right\ncorner while fading out. You can do this by creating a `\u003cKeyFrameSet\u003e` and\nadding a `\u003cKeyPosition\u003e` and `\u003cKeyAttribute\u003e` inside it. The `\u003cKeyPosition\u003e`\nspecifies the intermediate location of the ball, and the `\u003cKeyAttribute\u003e`\nspecifies that the ball remains opaque at the midpoint of the motion.\n\nSyntax\n------\n\n```xml\n\u003cKeyFrameSet\u003e\n [ \u003cKeyPosition/\u003e... ]\n [ \u003cKeyAttribute/\u003e...]\n\u003c/KeyFrameSet\u003e\n```\n\nContained in\n------------\n\n[`\u003cTransition\u003e`](/training/constraint-layout/motionlayout/ref/transition)\n\nContains\n--------\n\n[`\u003cKeyPosition\u003e`](/training/constraint-layout/motionlayout/ref/keyposition)\n: Specifies a view's position at a specific moment during the motion sequence.\n\n[`\u003cKeyAttribute\u003e`](/training/constraint-layout/motionlayout/ref/keyattribute)\n: Specifies view attributes at a specific moment during the motion sequence."]]