Android支持onLongPress事件。我的問題是「多久」(以毫秒爲單位)是觸發事件的'新聞'?Android中的onLongPress事件需要多長時間?
33
A
回答
36
標準長按時間是getLongPressTimeout()返回的值,它目前爲500毫秒,但可能會更改(1.0版本中爲1000毫秒,但在以後的版本中有所變化;將來可能會由用戶自定義)。
瀏覽器使用它自己的長按時間,因爲它有一些更復雜的相互作用。我相信這應該是1000,儘管它未來可能會改變。它不會將不同的超時加在一起。
17
您可以使用android.view.ViewConfiguration
的getLongPressTimeout
方法以編程方式確定該值。
詳見the docs。
1
嗯...我希望得到的累計時間。據我所知,getLongPressTimeout(),是確定事件按下時添加的組件時間加上TAP_TIMEOUT加上???如果在網頁瀏覽器中則爲1000毫秒。
我已經計算出它是1650ms,但是我想要確認一下結果的值。原因是我需要一些未與SDK集成的東西來預測長期持有。
我相信從getLongPressTimeout價值爲500ms,但手勢顯然需要更長的時間 - 接近2秒。
0
查看(並因此大部分它的子類)使用getLongPressTimeout。瀏覽器中的默認超時時間可能不足。
1
通常,like Roman Nurik mentioned,您可以使用ViewConfiguration.getLongPressTimeout()以編程方式獲取長按值的值。默認值是500ms。
/**
* Defines the default duration in milliseconds before a press turns into
* a long press
*/
private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;
但是,長按持續時間是可定製的全球通過設置它的可訪問性。值爲短(400毫秒),中(1000毫秒)或長(1500毫秒)。你可以看到它的源代碼在Settings:
// Long press timeout.
mSelectLongPressTimeoutPreference =
(ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE);
mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this);
if (mLongPressTimeoutValueToTitleMap.size() == 0) {
String[] timeoutValues = getResources().getStringArray(
R.array.long_press_timeout_selector_values);
mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
String[] timeoutTitles = getResources().getStringArray(
R.array.long_press_timeout_selector_titles);
final int timeoutValueCount = timeoutValues.length;
for (int i = 0; i < timeoutValueCount; i++) {
mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
}
}
0
這是R.array.long_press_timeout_selector_titles樣子:
<!-- Titles for the list of long press timeout options. -->
<string-array name="long_press_timeout_selector_titles">
<!-- A title for the option for short long-press timeout [CHAR LIMIT=25] -->
<item>Short</item>
<!-- A title for the option for medium long-press timeout [CHAR LIMIT=25] -->
<item>Medium</item>
<!-- A title for the option for long long-press timeout [CHAR LIMIT=25] -->
<item>Long</item>
</string-array>
<!-- Values for the list of long press timeout options. -->
<string-array name="long_press_timeout_selector_values" translatable="false">
<item>400</item>
<item>1000</item>
<item>1500</item>
</string-array>
相關問題
- 1. 我如何時間多長時間的事情需要在android
- 2. TopicClient需要多長時間?
- 3. GC需要多長時間?
- 4. NSCalendarUnitEra需要多長時間?
- 5. 測試套件需要多長時間?
- 6. 時間需要多長時間
- 7. 自定義事件顯示需要多長時間?
- 8. 在Android SharedPreferences中存儲數據需要多長時間?
- 9. NestedScrollView&RecyclerView,onLongPress事件
- 10. Android Publishing需要很長時間
- 11. Chrome事件觸發在大型DOM中需要很長時間
- 12. MySQL的 - 需要長時間
- 13. 運行scipy.test('full')需要多長時間?
- 14. 執行腳本需要多長時間?
- 15. 主鍵刪除需要多長時間?
- 16. printk命令需要多長時間?
- 17. CreateThread需要執行多長時間?
- 18. 需要多長時間學習backbone.js
- 19. Compact Framework和JIT。需要多長時間
- 20. SHA256散列需要多長時間?
- 21. Glibc需要多長時間來編譯?
- 22. C2DM註冊需要多長時間
- 23. 使用TDD需要多長時間?
- 24. 插入150K行需要多長時間?
- 25. 密碼認證需要多長時間?
- 26. CFmail需要發送多長時間?
- 27. 檢索數據需要多長時間?
- 28. 合同處理需要多長時間?
- 29. 執行循環需要多長時間?
- 30. 製作rabbitmq需要多長時間?
你確定這件事嗎?我的觀察結果是在網絡瀏覽器上1650毫秒(1750毫秒以確定其他處理負載)。你可以網站一些實驗室筆記或Android文檔? – mobibob 2009-12-22 23:08:22
..另外,查看源代碼,LONG時間直到檢測到短按之後纔開始其時間測量。這就是爲什麼我認爲這是累積在國家。 我不是在挑戰你的陳述,只是討論確定答案是徹底的,我的問題不會被誤解。 – mobibob 2009-12-22 23:12:34
不幸的是(對我來說)這是我的問題唯一正確的答案。但是......我真正想學的是從按下開始到瀏覽器彈出「解析器」對話框的時間。我測量1.650秒,所以我想找到缺少的650毫秒。我會將答案授予hackbod,並感謝所有人的評論。 – mobibob 2009-12-27 04:20:31