Android 设置长按响应时间,Android长按时长 默认时长 View配置

Android 关于View时间配置都放在了ViewConfig文件中/*** Defines the duration in milliseconds before a press turns into* a long press*/private static final int LONG_PRESS_TIMEOUT = 500; // t1完整的代码为:/** Copyright (C) 2...
摘要由CSDN通过智能技术生成

Android 关于View时间配置都放在了ViewConfig文件中

/**

* Defines the duration in milliseconds before a press turns into

* a long press

*/

private static final int LONG_PRESS_TIMEOUT = 500; // t1

完整的代码为:

/*

* Copyright (C) 2006 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

package android.view;

import android.app.AppGlobals;

import android.content.Context;

import android.content.res.Configuration;

import android.content.res.Resources;

import android.graphics.Point;

import android.os.RemoteException;

import android.provider.Settings;

import android.util.DisplayMetrics;

import android.util.SparseArray;

/**

* Contains methods to standard constants used in the UI for timeouts, sizes, and distances.

*/

public class ViewConfiguration {

/**

* Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in

* dips

*/

private static final int SCROLL_BAR_SIZE = 10;

/**

* Duration of the fade when scrollbars fade away in milliseconds

*/

private static final int SCROLL_BAR_FADE_DURATION = 250;

/**

* Default delay before the scrollbars fade in milliseconds

*/

private static final int SCROLL_BAR_DEFAULT_DELAY = 300;

/**

* Defines the length of the fading edges in dips

*/

private static final int FADING_EDGE_LENGTH = 12;

/**

* Defines the duration in milliseconds of the pressed state in child

* components.

*/

private static final int PRESSED_STATE_DURATION = 64;

/**

* Defines the default duration in milliseconds before a press turns into

* a long press

*/

private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;

/**

* Defines the time between successive key repeats in milliseconds.

*/

private static final int KEY_REPEAT_DELAY = 50;

/**

* Defines the duration in milliseconds a user needs to hold down the

* appropriate button to bring up the global actions dialog (power off,

* lock screen, etc).

*/

private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;

/**

* Defines the duration in milliseconds we will wait to see if a touch event

* is a tap or a scroll. If the user does not move within this interval, it is

* considered to be a tap.

*/

private static final int TAP_TIMEOUT = 100;

/**

* Defines the duration in milliseconds we will wait to see if a touch event

* is a jump tap. If the user does not complete the jump tap within this interval, it is

* considered to be a tap.

*/

private static final int JUMP_TAP_TIMEOUT = 500;

/**

* Defines the duration in milliseconds between the first tap's up event and

* the second tap's down event for an interaction to be considered a

* double-tap.

*/

private static final int DOUBLE_TAP_TIMEOUT = 300;

/**

* Defines the minimum duration in milliseconds between the first tap's up event and

* the second tap's down event for an interaction to be considered a

* double-tap.

*/

private static final int DOUBLE_TAP_MIN_TIME = 40;

/**

* Defines the maximum duration in milliseconds between a touch pad

* touch and release for a given touch to be considered a tap (click) as

* opposed to a hover movement gesture.

*/

private static final int HOVER_TAP_TIMEOUT = 150;

/**

* Defines the maximum distance in pixels that a touch pad touch can move

* before being released for it to be considered a tap (click) as opposed

* to a hover movement gesture.

*/

private static final int HOVER_TAP_SLOP = 20;

/**

* Defines the duration in milliseconds we want to display zoom controls in response

* to a user panning within an application.

*/

private static final int ZOOM_CONTROLS_TIMEOUT = 3000;

/**

* Inset in dips to look for touchable content when the user touches the edge of the screen

*/

private static final int EDGE_SLOP = 12;

/**

* Distance a touch can wander before we think the user is scrolling in dips.

* Note that this value defined here is only used as a fallback by legacy/misbehaving

* applications that do not provide a Context for determining density/configuration-dependent

* values.

*

* To alter this value, see the configuration resource config_viewConfigurationTouchSlop

* in frameworks/base/core/res/res/values/config.xml or the appropriate device resource overlay.

* It may be appropriate to tweak this on a device-specific basis in

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在Android中,我们可以通过设置 `OnLongClickListener` 来响应按钮的按操作。 首先,在布局文件中声明一个按钮: ```xml <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按按钮" /> ``` 接下来,在Java代码中找到该按钮并设置按监听器: ```java Button button = findViewById(R.id.button); button.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // 在这里实现按按钮后的逻辑 return true; // 返回 true 表示事件已处理,不会再触发短按事件 } }); ``` 在监听器的 `onLongClick` 方法中,我们可以实现按钮按后的逻辑。如果你希望按事件被消耗并且不再触发短按事件,可以返回 true。反之,如果还希望触发短按事件,可以返回 false。 例如,当用户按按钮时,我们可以显示一个提示对话框: ```java Toast.makeText(this, "按操作", Toast.LENGTH_SHORT).show(); ``` 以上便是在Android中响应按钮按操作的方法。 ### 回答2: 在Android中,可以通过设置按监听器来响应按钮的按操作。首先,需要在代码中找到要响应按操作的按钮控件。可以通过findViewById方法来获取按钮控件的引用。接下来,可以为按钮控件设置按监听器,使用setOnLongClickListener方法来注册监听器。 按监听器需要实现View.OnLongClickListener接口,并重写其中的onLongClick方法。在onLongClick方法中编写相应的逻辑代码,实现按钮按操作时需要进行的操作。 例如,可以在onLongClick方法中弹出一个对话框或显示一个菜单,提供用户进行额外的选择或操作。也可以通过改变按钮的外观或样式来提供视觉反馈,表示按钮按操作正在进行。 另外,还可以在按监听器中加入一些逻辑判断,来区分按钮的按操作和普通点击操作。比如,可以使用定时器来判断按钮按下的时间是否超过一定的阈值,从而区分按和点击操作。 需要注意的是,如果按钮同时设置了点击监听器和按监听器,在按操作时可能会触发点击监听器的点击事件。为了避免这种情况,可以在按监听器中返回true,表示已经处理了按事件,并阻止触发点击事件。 通过以上的步骤,就可以实现在Android中响应按钮的按操作了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值