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.