I have referenced manyCode. It cannot be dragged, extended, or shortened ··· So I tried to add them.
Now I will share it with you. Bytes --------------------------------------------------------------------------------------------------------- There are two implementation methods.
The first implementation method:
A main view class (a custom view) defines a unified painting, bitmap, and canvas in the main view class, as well as the three downpoints and movepoints that need to be used in the subclass, uppoint. Other sub-classes (the view that draws a straight line and the view that draws a rectangle...) inherit this main view class.
When selecting a shape each time: 1. instantiate a View class. 2. Add the View class to the current activity.
Each shape is drawn on its own view. The newly added view overwrites the previous view.
Each subclass has a method. Ontouchevent () Perform your own operations:
Public Boolean ontouchevent (motioneventevent) {[/align] switch (event. getaction () {casemotionevent. action_down: casemotionevent. action_move: casemotionevent. action_up:} return true ;}
Disadvantages: It is called every time you select a shape. Master View Class Bitmap = bitmap. createbitmap (480,700, bitmap. config. argb_8888 );// Set the width and height of the bitmap. Canvas = new canvas (Bitmap ); To recreate Bitmap , If you keep choosing, you will not stop creating Bitmap . Bitmap When too many instances are created, the following error occurs: memory overflow. Error.
Specific implementation methods: The specific implementation method of drawing, such as: how to drag a straight line? And so on. I have made a detailed comment in the code, and I believe everyone can understand it. Download the code for details. If you have any questions, please contact us and I will try my best to answer them.
Conclusion: There are still many imperfections in this small project. You are welcome to provide valuable suggestions and propose improvement methods. If you download the Code better, I hope you can send it to me. Let's make improvements together. Thank you.
Effect:
Source code: drawdemo01.rar
Bytes ---------------------------------------------------------------------------------------------------------
Method 2:
It is much better than the first implementation method, and the entire project looks more systematic.
InDrawdemo01Added the functions of rubber, clear, save, and view images.
The specific implementation method of source code annotation is clearly written. If you are interested, download it yourself.
Effect:
Source code: drawdemo02.rar