Drawing software that can be extended, shortened, and dragged

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.