Android implements a way to move a picture on the screen (drag-and-drop function) _android

Source: Internet
Author: User
Tags sqlite database

The example in this article describes how Android implements a way to move a picture around the screen arbitrarily. Share to everyone for your reference, specific as follows:

public class Dragexampleactivity extends activity {Bitmap mbitmap; /** called the activity is a.
    * * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Mbitmap = Bitmapfactory.decoderesource (Getresources (), R.drawable.icon);
  Setcontentview (This) (new Dragview);
    } @Override protected void OnDestroy () {Super.ondestroy ();
      if (null!= mbitmap) {mbitmap.recycle ();
    Mbitmap = null;
    } private class Dragview extends View {private int mmotionx = 0;
    private int mmotiony = 0;
    Private Paint Paint;
      Public Dragview {Super (context);
    Paint = new paint ();
      @Override public void Draw (Canvas Canvas) {Super.draw (Canvas);
    Canvas.drawbitmap (Mbitmap, Mmotionx, mmotiony, paint);
      @Override public boolean ontouchevent (motionevent ev) {if (ev.getaction () = = Motionevent.action_down)
 {       Mmotionx = (int) ev.getx ();
        Mmotiony = (int) ev.gety ();
        Invalidate ();
      return true;
      }else {return super.ontouchevent (EV);

 }
    }
  }
}

More interested readers of Android-related content can view the site: "A summary of Android photography and photo processing tips", a summary of the activity tips for Android programming, a summary of Android view View tips, Android Operation SQLite Database skills Summary, "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card operation method Summary", " Android Development Primer and Advanced tutorials, Android Resource operations tips and Android Control usage summary

I hope this article will help you with the Android program.

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.