Android custom view implementation method example of game rocker keyboard
preface
This article mainly introduces the content related to the implementation of game rocker keyboard by Android custom view. Why is there this article? Because in the previous project, the operation direction is up, down, left and right, and the upper left needs to press and hold the left and right keys at the same time.
As shown below:
Recently, the project needs to be upgraded, and the operation mode is changed to rocker operation similar to the glory of the king.
As shown below:
Well, I won't say much below. Follow Xiaobian to see how it is realized.
Draw background
To realize the remote sensing button, you need to draw the background and draw the remote sensing button in the center. To draw the remote sensing background, you need to create a remoteviewbg class to store the background map and reduce the repeated creation of bitmap.
The remoteviewbg class code is as follows:
Click touch event
Rewrite the touch time of the system to judge whether the touch point is within or outside the background range
Radian calculation
Obtain the current touch point through event. Getx(), event. Gety(), calculate with the dot, and obtain the radian
Graphic drawing
Use canvas. Drawcircle() and canvas. Drawbitmap() to draw the remote sensing button and remote sensing background respectively. Pay attention to saving the remote sensing background. If bitmapfactory. Decoderesource() will increase the time consumption during drawing, you only need to generate bitmap in surfacecreated().
use
Dynamically add in activity
All codes
summary
The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.