我怎样才能使一个按钮更加敏感? [英] How can I make a Button more responsive?

查看:129
本文介绍了我怎样才能使一个按钮更加敏感?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到,一些按钮看起来不够敏感,因为它们可能。这同样适用于我的应用程序,并以我试过其他大多数应用程序。

I have noticed that some Buttons don't seem as responsive as they could be. This applies equally to my app and to most other apps I've tried.

当我preSS一个按钮有滞后一点点(编辑:我估计约20-50毫秒)前的按钮点亮在pressed状态。一些应用程序已成功消除滞后该位,例如RealCalc(在市场上)的按钮后,你立即切换到pressed状态preSS你的手指在他们身上。

When I press a Button there is a tiny bit of lag ( I would estimate about 20-50 ms) before the Button lights up in the pressed state. Some apps have managed to remove this bit of lag, for instance RealCalc (available in the Market) whose Buttons switch to the pressed state immediately after you press your finger on them.

大多数时候这种滞后并不明显,但在我的情况下按钮是在自定义的数字键盘使用,滞后这一点点是颠覆性的用户。 RealCalc感觉这么多敏感和抛光,因为这种滞后已被删除。

Most of the time this lag is not noticeable, but in my case where the Buttons are used in a custom number pad, this tiny bit of lag is disruptive to the user. RealCalc feels so much more responsive and polished because this lag has been removed.

我的问题是 - 如何删除这个滞后?我知道我可以只子类,覆盖的onTouchEvent并从那里出发,但我真的preFER仅使用标准的控制和选项的解决方案。我怀疑该解决方案还可以干扰滚动,但我可以忍受的。

My question is - how do I remove this lag? I am aware that I could just subclass, override onTouchEvent and proceed from there, but I would really prefer a solution using just the standard controls and options. I suspect the solution may also interfere with scrolling, but I can live with that.

编辑:具体来说,所提到的滞后是你把你的手指上的一个按钮,并按住,直到按钮切换到pressed状态的时间。的onclick处理程序被调用时,你再松开手指。

Specifically, the lag mentioned is the time from you put your finger on a button and hold it there until the button switches to the pressed state. The onClick handler is called when you remove your finger again.

一些答案​​建议把大部分我onclick处理程序的一个线程。这不是问题。为了以防万一,我已经删除了所有点击处理,和微小的滞后性仍然存在。

Some answers suggested moving the bulk of my onClick handler to a thread. This is not the issue. To make doubly sure, I have removed all click handlers, and the tiny lag is still there.

推荐答案

我已经挖成Android源$ C ​​$ C,看看发生了什么事情。

I have dug into the Android source code to see what was going on.

事实证明,在android.view.View类(从哪些按钮派生)进入再进preSSED状态的pre preSSED状态:

It turns out that the android.view.View class (from which Button derives) enters a "PREPRESSED" state before going into the PRESSED state:

android.view.View:

android.view.View:

1529    /**
1530      * Indicates a prepressed state;
1531      * the short time between ACTION_DOWN and recognizing
1532      * a 'real' press. Prepressed is used to recognize quick taps
1533      * even when they are shorter than ViewConfiguration.getTapTimeout().
1534      * 
1535      * @hide
1536      */
1537     private static final int PREPRESSED             = 0x02000000;

android.view.ViewConfiguration.getTapTimeout()是115毫秒对我的Nexus One,这比我估计的长了很多。

android.view.ViewConfiguration.getTapTimeout() is 115 ms on my Nexus One, which is a lot longer than my estimation.

android.view.ViewConfiguration:

android.view.ViewConfiguration:

67     /**
68      * Defines the duration in milliseconds we will wait to see if a touch event 
69      * is a tap or a scroll. If the user does not move within this interval, it is
70      * considered to be a tap. 
71      */
72     private static final int TAP_TIMEOUT = 115;

总之,从检查View.onTouchEvent是看起来不象有一种方法,以避免任何标准选项pSSED状态,这pre $ P $。这是一个真正的耻辱。

Anyway, from examining View.onTouchEvent is doesn't look like there's a way to avoid this PREPRESSED state by any standard option. Which is a real shame.

好消息是,我现在已经证实,为了避免这种滞后的方式是继承和覆盖的onTouchEvent。

The good news is that I have now verified that the way to avoid this lag is to subclass and override onTouchEvent.

谢谢你的讨论和解答。

这篇关于我怎样才能使一个按钮更加敏感?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆