自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
触感反馈用户体验设计
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 HAL 和 API 之间映射常量中引入的 HAL-API 常量映射基于一些高度推荐的用户体验设计原则。这些用户体验设计原则定义了有关使用 Android 触感反馈 API 时的方法、时间以及使用要素。如需详细了解这些基础原则,请参阅高级触感反馈:全新触感反馈 API 的使用时间、要素和方法。
图 1. HAL-API 常量映射:离散模型
选择触感反馈效果
按触感反馈强度 (VibrationEffect
)
EFFECT_CLICK
是确定您偏好的触感反馈强度 (VibrationEffect
) 的最佳起点:它是介于 EFFECT_TICK
的“轻”触感和 EFFECT_HEAVY_CLICK
的“重”触感之间的中间值。从 EFFECT_CLICK
开始,您可以使用 EFFECT_HEAVY_CLICK
来增加强度,也可以使用 EFFECT_TICK
来降低强度,从而增加或降低概念性能量。请注意,EFFECT_DOUBLE_CLICK
可提供最高的概念性能量,因为它是可重复的。
图 2. 触感反馈强度设置
如果您的目标与特定的输入事件(例如长按或滑动)或界面元素(如键盘)相关,请在 HapticFeedbackConstants
中查找预定义的触感反馈常量。每个常量的名称都表示特定的用例,例如 KEYBOARD_PRESS
或 LONG_PRESS
。
输入事件(虚拟软键)的轻触触感反馈可模拟物理实体(例如机械硬键)的按钮按下操作。
输入事件:成对交互流
点击事件旨在模拟机械按钮的行为,使用这类按钮的方式为先按下,然后松开。按下按钮感觉到的机械推动力强度高于松开按钮。因此,按下按钮的触感反馈比松开按钮的触感反馈更为强烈。
图 3. 二进制输入事件产生的触感反馈效果
触感反馈强度:按下按钮动作
互动时间较短、较快的输入事件与“更轻”触感反馈关联。互动时间较长、较深的输入事件与“强烈”触感反馈关联。
图 4. 动作的触感反馈效果
在手势输入事件中模拟虚拟纹理
当手指在屏幕的视觉界面上移动时,基于手势的输入(例如拖动或滚动)可以与虚拟触感反馈纹理相匹配,例如,当手指在包含虚拟刻度标记界面元素的时钟界面上移动时,产生重复的触感反馈。
虚拟触感反馈纹理的效果是重复性的。这通常会导致感知的能量高于实际幅度(当效果未重复,或仅发生了一次)。因此,专为虚拟触感纹理(例如 CLOCK_TICK
或 TEXT_HANDLE_MOVE
)设计的触感反馈常量必须足够细微,以便通过重复提示来产生移动的感觉。
图 5.用于模拟虚拟纹理的触感效果
包含情绪
若要在触感反馈效果中包含正面情绪或负面情绪,请对负面情绪施加更强的感觉,以引起用户的注意。
图 6. 包含情绪的触感效果
避免长时间振动时发出可听见的噪声
为避免因长时间振动来引起注意而产生可听见的噪声,请平滑地加速以产生逐步提升效果。您可以使用 createWaveform(long[] timings, int[] amplitudes, int repeat)
执行此操作。
图 7. 长时间振动逐步提升效果
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-10。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-10。"],[],[],null,["# Haptics UX design\n\nThe HAL-API constants mapping introduced in [Map constants between HAL and API](/docs/core/interaction/haptics/haptics-map-constants)\nis driven by highly recommended UX design principles.\nThe UX design principles define the foundation of how, when, and what to use\nwhen using Android haptics APIs. See\n[Advanced Haptics: The When, What, and How of New Haptic APIs](https://youtu.be/00jRoEFnpk8)\nto learn more about these foundational principles.\n\n**Figure 1.** HAL-API constant mapping: Discrete model\n\nSelect haptic effects\n---------------------\n\n### By haptic strength (`VibrationEffect`)\n\n`EFFECT_CLICK` is the best place to start when determining your preferred haptic\nstrength ([`VibrationEffect`](https://developer.android.com/reference/android/os/VibrationEffect)):\nit's the median between the \"light\" haptics of `EFFECT_TICK` and the\n\"heavy\" haptics of `EFFECT_HEAVY_CLICK`. By starting with `EFFECT_CLICK`, you\ncan increase or decrease the conceptual energy by adding strength with\n`EFFECT_HEAVY_CLICK`, or decrease strength with `EFFECT_TICK`. Keep in mind,\n`EFFECT_DOUBLE_CLICK` delivers the highest conceptual energy because it's\nrepeated.\n\n**Figure 2.** Haptic strength settings\n\n### By input events and UI elements (`HapticFeedbackConstants`)\n\nIf your goal is associated with specific input events (like long press, or\nswipe), or UI elements (like keyboard), find predefined haptic constants in\n[`HapticFeedbackConstants`](https://developer.android.com/reference/android/view/HapticFeedbackConstants).\nThe name of each constant refers to specific use cases like `KEYBOARD_PRESS`, or\n`LONG_PRESS`.\n\nSimulate real-world button-press events\n---------------------------------------\n\nThe touch haptic feedback of input events (virtual soft buttons) can simulate\nbutton presses using physical entities (such as mechanical hard buttons).\n\n### Input event: Pairwise interaction flow\n\nThe click event is designed to simulate the behavior of a mechanical button,\nwhich is *pressed* then *released*. The perceived energy of the mechanical\nimpulse from a button press is higher than that of a button release. Therefore,\nthe haptic feedback for button presses is stronger than the haptic feedback for\nbutton releases.\n\n**Figure 3.** Haptic effects by binary input event\n\n### Haptic strength: The affordance of button press\n\nInput events with shorter and lighter engagement are associated with *lighter*\nhaptics. Input events with longer and deeper engagement are associated with\n*stronger* haptics.\n\n**Figure 4.** Haptic effects by affordance\n\nSimulate virtual texture in gesture input event\n-----------------------------------------------\n\nGesture-based input (like scrubbing or scrolling) can be aligned with virtual\nhaptic textures while the finger is moving on the screen along with visual UIs,\nfor example, generating repeated haptic feedback while a finger is moving around\nthe clock UI with virtual tick mark UI elements.\n\nEffects for virtual haptic textures are meant to be repeated. This often makes\nthe perceived energy higher than the amplitude (when the effect is called\n*without repetition* , or *only once* ). Because of this, haptic constants that\nare designed for virtual haptic textures (like `CLOCK_TICK` or\n`TEXT_HANDLE_MOVE`) must be *subtle* to provide the feeling of movement through\nrepeated cues.\n\n**Figure 5.** Haptic effects to simulate virtual texture\n\nInclude sentiments\n------------------\n\nTo include positive or negative sentiment in haptic effects, apply stronger\nsensation to negative sentiment to get the user's attention.\n\n**Figure 6.** Haptic effects with sentiment\n\nAvoid audible noise from long vibration\n---------------------------------------\n\nTo avoid audible noise from long vibration for attentional haptics, accelerate\nthe pattern smoothly to create a ramp-up effect. Do this by using\n[`createWaveform(long[] timings, int[] amplitudes, int repeat)`](/docs/core/interaction/haptics/haptics-ux-foundation#ease-in).\n\n**Figure 7.** Long vibration ramp-up effect"]]