Android custom view circle and drag circle follow finger drag
Simply customizing a circle is very simple. It only takes a few steps to drag the circle to add and realize the touch event
Small problems I encountered in customizing the view circle for the first time:
1. If you drag a circle, the width and height of the custom circle set in the XML is the size of the space it can move, not the size of the circle control. If you define 100dp, if you drag it more than 100dp, the circle will be invisible. As shown below, if you want to move on the whole screen, match the width and height directly_ Just the parent attribute
2. The customized view in the layout will prompt you to compile. Just click build to compile
Let's start writing code: first, simply create a circle, create a class, inherit view, and implement OnDraw method
Name of self defined view class in XML:
Once a circle is created, it can be run directly. There is no need to change anything in manactivity
The following is the function of adding and dragging circles. It is very simple to realize touch monitoring. There are very few codes as follows:
In this way, the circle moves with the movement of your fingers. Try it quickly.