Android plotting learning-Tablet

Source: Internet
Author: User

:

View code: display the view in the activity.

Package COM. tszy. view; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmap. config; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. path; import android. view. motionevent; import android. view. view;/*** dual-buffer drawing demo tablet ** @ author jianbinzhu **/public class view7 extends view {private paint; private canvas cachecanvas; private bitmap cachebbitmap; private Path; Public view7 (context) {super (context); // todo auto-generated constructor stubpaint = new paint (); paint. setantialias (true); paint. setstrokewidth (3); paint. setstyle (paint. style. stroke); paint. setcolor (color. cyan); Path = New Path (); cachebbitmap = bitmap. createbitmap (480,320, config. argb_8888); cachecanvas = new canvas (cachebbitmap);} @ overrideprotected void ondraw (canvas) {canvas. drawcolor (color. black); // draw the last image; otherwise, the canvas is inconsistent. drawbitmap (cachebbitmap, 0, 0, null); canvas. drawpath (path, paint);} private float cur_x, cur_y; private Boolean ismoving; @ overridepublic Boolean ontouchevent (motionevent event) {// todo auto-generated method stubfloat x = event. getx (); float y = event. gety (); Switch (event. getaction () {Case motionevent. action_down: {cur_x = x; cur_y = y; Path. moveTo (cur_x, cur_y); ismoving = true; break;} case motionevent. action_move: {// draw the path using the quadratic curve. quadto (cur_x, cur_y, x, y); // The following method looks like above // path. lineto (x, y); cur_x = x; cur_y = y; break;} case motionevent. action_up: {// click it to save the last state of cachecanvas. drawpath (path, paint); Path. reset (); ismoving = false; break ;}// refresh the interface invalidate (); Return true ;}}

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.