# 震動致動器入門

LRA 的一項常見功能，是模擬按鈕點選無回應玻璃表面的感受。能讓使用者互動感覺更自然。在虛擬鍵盤上輸入內容時，點按意見回饋可提高輸入速度並減少錯誤。如果點擊回饋信號呈現清晰簡潔，持續時間通常不到 10 到 20 毫秒。如要獲得好的點擊，您必須對裝置中使用的 LRA 有所瞭解。因此，採用預製波形可提供最佳點擊回饋。每當需要點擊意見回饋時，您都可以將這些常數與平台提供的常數搭配使用。

### Kotlin

```val timings: LongArray = longArrayOf(50, 50, 50, 50, 50, 100, 350, 250)
val amplitudes: IntArray = intArrayOf(77, 79, 84, 99, 143, 255, 0, 255)
val repeatIndex = -1 // Do not repeat.

vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, repeatIndex))
```

### Java

```long[] timings = new long[] { 50, 50, 50, 50, 50, 100, 350, 250 };
int[] amplitudes = new int[] { 77, 79, 84, 99, 143, 255, 0, 255 };
int repeatIndex = -1 // Do not repeat.

vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, repeatIndex));
```

### Kotlin

```val timings: LongArray = longArrayOf(
25, 25, 50, 25, 25, 25, 25, 25, 25, 25, 75, 25, 25,
300, 25, 25, 150, 25, 25, 25
)
val amplitudes: IntArray = intArrayOf(
38, 77, 79, 84, 92, 99, 121, 143, 180, 217, 255, 170, 85,
0, 85, 170, 255, 170, 85, 0
)
val repeatIndex = -1 // Do not repeat.

vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, repeatIndex))
```

### Java

```long[] timings = new long[] {
25, 25, 50, 25, 25, 25, 25, 25, 25, 25, 75, 25, 25,
300, 25, 25, 150, 25, 25, 25
};
int[] amplitudes = new int[] {
38, 77, 79, 84, 92, 99, 121, 143, 180, 217, 255, 170, 85,
0, 85, 170, 255, 170, 85, 0
};
int repeatIndex = -1; // Do not repeat.

vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, repeatIndex));
```

• 執行清晰的特效和原始物件

• 串連後即可撰寫新的觸覺效果。

[]
[]