Getlocationonscreen , calculates the x, Y value of the view in the global coordinate system (note that this value is calculated from the top of the screen, i.e. the height of the notification bar is included)//Gets the absolute coordinates in the current screen
Getlocationinwindow , calculates the x, Y value of the view in its widnow coordinates,//Gets the absolute coordinates within the entire window (not very understanding = =,)
getLeft , getTop, getbottom,getRight, this group is getting the coordinates relative to its father
If the OnCreate () event of the activity outputs those parameters, it is all 0, so that the UI controls are loaded before they can be obtained.
[Java]View PlainCopy 
 
 
 - Package xiaosi.location;
  
 
  
 
 - Import android.app.Activity;
  
 
 - Import Android.os.Bundle;
  
 
 - Import Android.view.View;
  
 
 - Import Android.view.View.OnClickListener;
  
 
 - Import Android.widget.Button;
  
 
 - Import Android.widget.ImageView;
  
 
  
 
 - Public class Locationactivity extends Activity { 
  
 
 - /** Called when the activity is first created. * /
  
 
 - private ImageView t = null; 
  
 
 - Private button button = null; 
  
 
 - @Override
  
 
 - public void OnCreate (Bundle savedinstancestate) { 
  
 
 - super.oncreate (savedinstancestate); 
  
 
 - Setcontentview (R.layout.main);
  
 
  
 
 - t = (ImageView) Findviewbyid (R.ID.L);
  
 
 - Button = (button) Findviewbyid (R.id.button);
  
 
 - Button.setonclicklistener (new Buttonlistener ()); 
  
 
 - }
  
 
 - public class Buttonlistener implements onclicklistener{  
  
 
  
 
 - public void OnClick (View v) 
  
 
 - {
  
 
 - int[] location = new int[2]; 
  
 
 - T.getlocationonscreen (location);
  
 
 - int x = location[0]; 
  
 
 - int y = location[1]; 
  
 
 - System.out.println ("x:" +x+"y:" +y); 
  
 
 - System.out.println ("picture Corners Left:" +t.getleft () +"right:" +t.getright () +"Top:" +t.gettop () +"Bottom:" +  T.getbottom ()); 
  
 
 - }
  
 
 - }
  
 
 - }
  
[Java]View PlainCopy 
 
 
 - <?xml version="1.0" encoding="Utf-8"?> 
  
 
 - <linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"
  
 
 - Android:layout_width="Fill_parent"
  
 
 - android:layout_height="Fill_parent"
  
 
 - android:orientation="vertical" >
  
 
  
 
 - <button
  
 
 - android:id="@+id/button"
  
 
 - Android:layout_width="Fill_parent"
  
 
 - android:layout_height="Wrap_content"
  
 
 - android:text="button"/>
  
 
 - <imageview
  
 
 - android:id="@+id/l"
  
 
 - Android:layout_width="Wrap_content"
  
 
 - android:layout_height="Wrap_content"
  
 
 - android:layout_gravity="center"
  
 
 - android:src="@drawable/a"/>
  
 
 - </LinearLayout>
  
Android gets the coordinates of the control in the screen