掃二維碼與項目經理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流

java.lang.Object
|---ohos.agp.components.VelocityDetector
public final class VelocityDetector
extends Object用于檢測觸摸事件速度的助手,用于實現(xiàn)投擲和其他類似手勢。
Since:
3
| 修飾符和類型 | 類 | 描述 |
|---|---|---|
| protected static class | VelocityDetector.VelocityDetectorCleaner | 釋放原生 Style 對象的回調。 |
| 修飾符和類型 | 方法 | 描述 |
|---|---|---|
| void | addEvent(TouchEvent event) | 將用戶的移動添加到檢測器。 |
| void | calculateCurrentVelocity(int units) | 根據(jù)已收集的點計算當前速度。 |
| void | calculateCurrentVelocity(int units, float maxVxVelocity, float maxVyVelocity) | 根據(jù)已收集的點計算當前速度,并指定計算的 X 和 Y 速度的上限。 |
| void | clear() | 將 VelocityDetector 實例重置為初始狀態(tài)。 |
| float | getHorizontalVelocity() | 獲取最近計算的 X 速度。 |
| float[] | getVelocity() | 獲取最近計算的速度。 |
| float | getVerticalVelocity() | 獲取最近計算的 Y 速度。 |
| static VelocityDetector | obtainInstance() | 獲取一個新的 VelocityDetector 實例來檢測運動的速度。 |
| 從類 java.lang.Object 繼承的方法 |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
public static VelocityDetector obtainInstance()
獲取一個新的 VelocityDetector 實例來檢測運動的速度。
返回:
返回 VelocityDetector 實例。
Since:
4
public void clear()
將 VelocityDetector 實例重置為初始狀態(tài)。
public void addEvent(TouchEvent event)
將用戶的移動添加到檢測器。
您可以調用此方法來檢測任何運動。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| event | 表示您要檢測的事件,它是一個 TouchEvent 實例。 |
Since:
4
public void calculateCurrentVelocity(int units)
根據(jù)已收集的點計算當前速度。
計算完成后,您可以使用 getHorizontalVelocity() 和 getVerticalVelocity() 來檢索速度結果。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| units | 指示速度結果的單位。 值 1 表示每秒像素數(shù),1000 表示每秒像素數(shù),依此類推。 |
public void calculateCurrentVelocity(int units, float maxVxVelocity, float maxVyVelocity)
根據(jù)已收集的點計算當前速度,并指定計算的 X 和 Y 速度的上限。
計算完成后,您可以使用 getHorizontalVelocity() 和 getVerticalVelocity() 來檢索速度結果。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| units | 表示速度結果。 值 1 表示每秒像素數(shù),1000 表示每秒像素數(shù),依此類推。 |
| maxVxVelocity | 指示最大 X 速度。 |
| maxVyVelocity | 指示最大 Y 速度。 |
public float getHorizontalVelocity()
獲取最近計算的 X 速度。
在調用此函數(shù)之前,您必須先調用 calculateCurrentVelocity(int)。
返回:
返回最近計算的 X 速度。
Since:
4
public float getVerticalVelocity()
獲取最近計算的 Y 速度。
在調用此函數(shù)之前,您必須調用 calculateCurrentVelocity(int)。
返回:
返回最近計算的 Y 速度。
Since:
4
public float[] getVelocity()
獲取最近計算的速度。
在調用此方法之前,您必須調用 calculateCurrentVelocity(int)。
返回:
返回最近計算的速度。
Since:
4

我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流