前言
這個ViewConfiguration是Android 自帶View的常量配置類,用於保存了各類View的點擊、長按、拖動、滑動等等一些View的配置數據。我們在自定義View的時候可以參考這個類提取對應常量來實現與官方匹配的觸控手感。
ViewConfiguration 實例獲取
ViewConfiguration viewConfiguration = ViewConfiguration.get(Context);
常用對象方法
// 獲取touchSlop (系統 滑動距離的最小值,大於該值可以認為滑動) int touchSlop = viewConfiguration.getScaledTouchSlop(); // 獲得允許執行fling (拋)的最小速度值 int minimumVelocity = viewConfiguration.getScaledMinimumFlingVelocity(); // 獲得允許執行fling (拋)的最大速度值 int maximumVelocity = viewConfiguration.getScaledMaximumFlingVelocity(); // Report if the device has a permanent menu key available to the user // (報告設備是否有用戶可找到的永久的菜單按鍵) // 即判斷設備是否有返回、主頁、菜單鍵等實體按鍵(非虛擬按鍵) boolean hasPermanentMenuKey = viewConfiguration.hasPermanentMenuKey();
常用靜態方法
// 獲得敲擊超時時間,如果在此時間內沒有移動,則認為是一次點擊 int tapTimeout = ViewConfiguration.getTapTimeout(); // 雙擊間隔時間,在該時間內被認為是雙擊 int doubleTapTimeout = ViewConfiguration.getDoubleTapTimeout(); // 長按時間,超過此時間就認為是長按 int longPressTimeout = ViewConfiguration.getLongPressTimeout(); // 重復按鍵間隔時間 int repeatTimeout = ViewConfiguration.getKeyRepeatTimeout();