代码之家  ›  专栏  ›  技术社区  ›  mobibob

安卓系统中的onLongPress事件持续多长时间?

  •  36
  • mobibob  · 技术社区  · 15 年前

    Android支持onLongPress事件。我的问题是“按下”触发事件的时间有多长(以毫秒为单位)?

    6 回复  |  直到 15 年前
        1
  •  50
  •   naXa stands with Ukraine    10 年前

    标准长按时间是返回的时间 getLongPressTimeout() ,当前为500毫秒,但可能会更改(在1.0中为1000毫秒,但在以后的版本中更改;也许将来它将是用户可定制的)。

    浏览器使用自己的长按时间,因为它有一些更复杂的交互。我相信这个数字应该是1000,尽管将来可能会改变。它不是将不同的超时加在一起。

        2
  •  19
  •   Roman Nurik    15 年前

    getLongPressTimeout 方法 android.view.ViewConfiguration 以编程方式确定此值。

    看见 the docs

        3
  •  4
  •   Tim Kist    7 年前

    通常地 like Roman Nurik mentioned ViewConfiguration.getLongPressTimeout()

    /**
     * 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]);
        }
    }
    
        4
  •  3
  •   Viking Den    7 年前

    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>
        5
  •  1
  •   mobibob    15 年前

    六羟甲基三聚氰胺六甲醚。。。我希望得到累计时间。据我所知, getLongPressTimeout()

    我已经计算出它是1650ms,但是我想确认一下 结果

    我相信getLongPressTimeout的值是500毫秒,但这个手势显然需要更长的时间——接近2秒。

        6
  •  0
  •   James    15 年前

    视图(及其大多数子类)使用getLongPressTimeout。在浏览器中,默认超时可能不够。