The example in this article tells you that Android implements object move/control drag based on widget components. Share to everyone for your reference, specific as follows:
Package Com.sky;
Import android.app.Activity;
Import Android.os.Bundle;
Import android.view.KeyEvent;
Import android.view.MotionEvent;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.AbsoluteLayout;
Import Android.widget.Button; @SuppressWarnings ("deprecation") public class Abosolutemove extends activity implements Onclicklistener {/** when The activity is the created.
* * Public Button button1;
Public Button button2;
Public Button Button3;
Public Button Button4;
Button tmp;//temporarily save, select button int x;
int y; The int flag;//is used to flag which button is selected @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (Savedinstan
Cestate);
Setcontentview (R.layout.main);
button1= (Button) Findviewbyid (r.id.widget27);
Button2= (Button) Findviewbyid (R.ID.WIDGET28);
button3= (Button) Findviewbyid (r.id.widget29);
button4= (Button) Findviewbyid (R.ID.WIDGET30);
Button1.setonclicklistener (this); Button2.setonclickliStener (this);
Button3.setonclicklistener (this);
Button4.setonclicklistener (this); @Override public void OnClick (View v) {//TODO auto-generated Method Stub switch (V.getid ()) {case R.id.widget2
7:flag=r.id.widget27;
Settitle ("Button1");
Break
Case R.id.widget28:flag=r.id.widget28;
Settitle ("Button2");
Break
Case r.id.widget29:flag=r.id.widget29;
Settitle ("Button3");
Break
Case R.id.widget30:flag=r.id.widget30;
Settitle ("Button4");
Break @Override public boolean onKeyDown (int keycode, keyevent event) {//TODO auto-generated a stub return Supe
R.onkeydown (KeyCode, event); @Override public boolean ontouchevent (Motionevent event) {//TODO auto-generated method Stub x = (int) Event.getx (
);
y = (int) event.gety (); tmp= (Button) Findviewbyid (flag);//Get selected Button absolutelayout.layoutparams params1=new absolutelayout.layoutparams
(50,50,X-25,Y-50); Tmp.setlayoutparams (PARAMS1);/Set the new location of the button SWItch (Event.getaction ()) {case MotionEvent.ACTION_DOWN:tmp.invalidate ();
Tmp.settext ("checked down");
Break
Case MotionEvent.ACTION_UP:tmp.invalidate ();
Tmp.settext ("checked up");
Break
Case MotionEvent.ACTION_MOVE:tmp.invalidate ();
Tmp.settext ("select Move");
Break
Return Super.ontouchevent (event);
}
}
More interested readers of Android-related content can view this site: "Summary of Android Basic components Usage", "Introduction to Android Development and advanced Tutorials", "Android resource Operation Tips", "Android View tips Summary" and " A summary of the usage of Android controls
I hope this article will help you with the Android program.