Android Small App-----drawing board

Source: Internet
Author: User
Tags gety

public class Mainactivity extends Activity {private ImageView iv;float StartX = 0;float Starty = 0;//Get a can be bitmapbitmap b Itmap = Bitmap.createbitmap (n, 400,bitmap.config.argb_8888);//Create a canvas canvas canvas = new canvas (BITMAP);//Create Brush Paint Paint = new Paint (), @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); iv = (ImageView) This.findviewbyid (R.ID.IV);p Aint.setcolor (Color.Black); Paint.setstrokewidth (1);//Set Pixel Iv.setontouchlistener (new Ontouchlistener () {@Overridepublic Boolean onTouch (View V, Motionevent event) {switch (event.getaction ()) {Case MotionEvent.ACTION_DOWN:startX = Event.getx (); starty = Event.gety ( ); Break;case MotionEvent.ACTION_MOVE:float newx = Event.getx (); Float newy = Event.gety (); Canvas.drawline (StartX, Starty, Newx, newy, paint); Iv.setimagebitmap (bitmap); break;case Motionevent.action_up:break;default:break;} return true;});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//InflatE the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}

Related Article

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.