I needed to implement the Button class for the touchscreen. (Do not use a ready-made solution) (The question is not tied to a specific platform, only the principle is interested)

As an Android user, I, of course, understand that if just tracking a touchDown hit on a button and activating it onClick by touchUp is not an option. The user can put his finger on the button, then change his mind and move it. He will raise it no longer within the borders of the button, but it will still click.

You can additionally track that the touchUp was also produced within the boundaries of the button. But it is still not very convenient for the user when the button is large.

Then, having a little libgdx libgdx button implementation, I found something like tap square . As I understand it, this is something like a square around the point where the user clicked. If he raised his finger within the boundaries of the box && within the borders of the button, then the click passes. Well, it's logical.

The easiest way to track the distance between the point at which the user pressed the button and the point at which he raised his finger. If this distance is less than the maximum, then call onClick . Then how to adjust the distance? And after all it needs to be configured not just in pixels, but taking into account dpi ? My version seems to be fine with me, but I would like to know if this is usually done in this way, or am I missing something?

Links are welcome.

  • onClickListener not suitable? - iamtihonov
  • @iamtihonov and what have some onClickListener ? Did you read the question? I ask not how to use something ready on the droid, but how it is implemented - selya
  • As it is, this is a standard mechanism. The fact that it does not suit you in the question you did not indicate and maybe you are creating a bike, especially since you are talking about some kind of simple tool in Android. I read your question. Specify your question more specifically and put it in the title. - iamtihonov
  • Мне понадобилось реализовать класс Button для сенсорного экрана . Do you know what is "implement"? I need to make a button for the engine, I'm interested in how it is done in different frameworks, for example, the default Button in Android, or the Button in libgdx . - selya
  • what if to look at source codes of the View class (from which all widgets in Android are inherited). Android - the system is open and its source is available in the same IDE, so as not to go far - pavlofff

0