Multi touch program of Android development example

The multi touch operation of intelligent terminal devices has brought us a variety of cool experiences, which also makes many Android developers interested in the development of multi touch programs. In fact, the implementation of multi touch program is not so far away, but relatively easy. This paper mainly explains the implementation of multi touch program through an example.

First, let's understand the principle of multi touch in Android.

Android multi touch essentially requires LCD driver and program design support. At present, well-known manufacturers such as HTC, Motorola and Samsung on the market can support multi touch multitouch technology as long as they use the touch principle of capacitive screen, which has a better user experience in web page scaling and gesture operation. On the Android platform, events are handled in the motionevent object mode. For example, action will be triggered when touch is started_ Down, and action when moving_ Move, the action is triggered when the finger is finally released_ Up event. Of course, there are also irregular operations of users that may trigger action_ Cancel this action.

For conventional touch operations, we use the ontouchevent() method implemented internally by the setontouchlistener() interface of view. Therefore, we need to understand the parameter motionevent of ontouchevent method, such as:

Java code

Next, we will explain how to realize multi touch according to a project.

Before the code, let's take a look at the running effect diagram of this example:

@H_ 419_ 25@

Here are the implementation steps:

1. Create an Android project named multitouchvisible.

2. In this project, we create a new view, inherit the surfaceview, and implement the callback interface. Here, we name this class MyView Java, the following is the specific implementation code of this class:

Java code

3. Modify the main activity class and display the view in setcontentview(). The specific implementation is as follows:

Java code

4. So far, the project has been completed. It can be seen that it is not difficult to realize multi touch! Run this example program to get the interface as shown in the effect picture above.

The above is the data sorting of Android multi touch. We will continue to sort out relevant data in the future. Thank you for your support to this site.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>