自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
觸覺回饋使用者體驗設計
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在「在 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. 觸覺回饋強度設定
如果您的目標與特定輸入事件 (例如長按或滑動) 或 UI 元素 (例如鍵盤) 相關,請在 HapticFeedbackConstants
中找出預先定義的觸覺回饋常數。每個常數的名稱都代表特定用途,例如 KEYBOARD_PRESS
或 LONG_PRESS
。
輸入事件 (虛擬軟體按鈕) 的觸控觸覺回饋功能,可模擬使用實體實體 (例如機械式實體按鈕) 按下按鈕的動作。
輸入事件:成對互動流程
點擊事件旨在模擬機械式按鈕的行為,也就是先「按下」再「放開」。按下按鈕時,機械衝動的感知能量會高於釋放按鈕時。因此,按下按鈕的觸覺回饋會比鬆開按鈕的觸覺回饋更強烈。
圖 3. 以二進位輸入事件產生的觸覺技術效果
觸覺回饋強度:按下按鈕的操作提示
參與度較短且較輕的輸入事件會與較輕的觸覺回饋相關聯。參與度較長且較深的輸入事件,會與更強烈的觸覺回饋相關聯。
圖 4. 依據操作空間產生的觸覺效果
在手勢輸入事件中模擬虛擬紋理
手勢輸入 (例如快速瀏覽或捲動) 可與虛擬觸覺紋理保持一致,同時在手指在畫面上移動時,搭配使用視覺 UI,例如在手指在時鐘 UI 中移動時,產生重複的觸覺回饋,並搭配使用虛擬勾號 UI 元素。
虛擬觸覺觸感紋理的效果是為了重複使用。這通常會讓感知能量高於振幅 (當效果不重複或只執行一次時)。因此,針對虛擬觸覺紋理 (例如 CLOCK_TICK
或 TEXT_HANDLE_MOVE
) 設計的觸覺常數必須「輕微」,才能透過重複的提示提供移動感。
圖 5. 模擬虛擬紋理的觸覺效果
納入情緒
如要在觸覺效果中加入正面或負面情緒,請將更強烈的感覺套用至負面情緒,以吸引使用者的注意。
圖 6. 情緒觸覺技術效果
避免長時間震動產生可聽見的噪音
為避免長時間振動造成的聲響,請平順地加速模式,產生漸進效果。請使用 createWaveform(long[] timings, int[] amplitudes, int repeat)
執行此操作。
圖 7. 長時間震動漸增效果
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],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"]]