Android dynamically draws a rectangular effect on the screen by touching
Requirements overview:
Draw an area with your finger on the screen and return the coordinates of the area circled.
Technical realization:
Customize the view, set the brush and corresponding parameters, and judge the touch event in the ontouchevent() callback function. Draw a rectangular shape.
Code:
Custom view:
When calling, you only need to add it directly in oncreate() function:
You can add a function that returns the delimited range in the user-defined class as needed.
PS: it should be noted that when the finger moves and the screen needs to update the rectangle, in principle, delete the original rectangle and draw a new rectangle. However, due to the thickness of the edge of the hollow rectangle,
In this case, the border thickness will be subtracted to solve the above problem.
design sketch:
The above is what Xiaobian introduced to you. Android dynamically draws a rectangular effect on the screen through touch. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!