Android development example simple graffiti board

Developing some small applications on Android can not only accumulate knowledge but also increase fun. It is different from task-based development. Therefore, it is a good way for us to realize a simple graffiti board on Android system.

Code implementation of graffiti board application

New project mywall, modify / RES / layout / main XML file, in which a surfaceview and two buttons are added. The relativelayout layout is used. The complete main The XML file is as follows:

XML/@R_ 502_ 1457@

Next, modify mywallactivity Java file, the most important thing is to rewrite the ontouchevent () function, filter out the touch screen drag event in this function, and then obtain its corresponding coordinates and lines. The complete contents are as follows:

Java code

Application test

Running this application on the simulator has the following effects:

The effect of running on Android phones is as follows:

The writing is a little ugly, but the function is realized. After obtaining the Y coordinate, subtract an offset value of 50. This value is guessed. Unexpectedly, it is quite accurate on the simulator and the real machine.

The application is relatively simple, but you can enrich its functions on this basis and make it a decent Android application.

The above is a simple example of Android simple graffiti board. Continue to sort out relevant materials in the future. Thank you for your support for 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
分享
二维码
< <上一篇
下一篇>>