本文介绍了如何配置的响应时间LongClick?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Android的, View.onLongClickListener()
大约需要1秒钟把它作为一个长期的点击。如何配置的响应时间很长的点击?
In Android, View.onLongClickListener()
takes about 1 sec to treat it as a long click. How can I configure the response time for a long click?
推荐答案
默认的超时是由<定义href="http://developer.android.com/reference/android/view/ViewConfiguration.html#getLong$p$pssTimeout%28%29"相对=nofollow> ViewConfiguration.getLong pressTimeout()
。
The default time out is defined by ViewConfiguration.getLongPressTimeout()
.
您可以实现自己的长期preSS:
You can implement your own long press:
boolean mHasPerformedLongPress;
Runnable mPendingCheckForLongPress;
@Override
public boolean onTouch(final View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
if (!mHasPerformedLongPress) {
// This is a tap, so remove the longpress check
if (mPendingCheckForLongPress != null) {
v.removeCallbacks(mPendingCheckForLongPress);
}
// v.performClick();
}
break;
case MotionEvent.ACTION_DOWN:
if( mPendingCheckForLongPress == null) {
mPendingCheckForLongPress = new Runnable() {
public void run() {
//do your job
}
};
}
mHasPerformedLongPress = false;
v.postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout());
break;
case MotionEvent.ACTION_MOVE:
final int x = (int) event.getX();
final int y = (int) event.getY();
// Be lenient about moving outside of buttons
int slop = ViewConfiguration.get(v.getContext()).getScaledTouchSlop();
if ((x < 0 - slop) || (x >= v.getWidth() + slop) ||
(y < 0 - slop) || (y >= v.getHeight() + slop)) {
if (mPendingCheckForLongPress != null) {
v. removeCallbacks(mPendingCheckForLongPress);
}
}
break;
default:
return false;
}
return false;
}
这篇关于如何配置的响应时间LongClick?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!