First of all, talk less, first on:
Code:
public class Mainactivity extends Activity implements onclicklistener{private button Showbtn1;private button showbtn2;@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main) showBtn1 = (Button) Findviewbyid (R.ID.SHOWBTN1); showBtn2 = (Button) Findviewbyid ( R.ID.SHOWBTN2); Showbtn1.setonclicklistener (this), Showbtn2.setonclicklistener (this);} @Overridepublic void OnClick (View v) {//TODO auto-generated method Stubview Popupview = Layoutinflater.from (this). Inflat E (r.layout.popup, NULL); Popupwindow Popupwindow = new Popupwindow (Popupview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, True);p opupwindow.setbackgrounddrawable (New bitmapdrawable ()); Popupview.measure (measurespec.unspecified, measurespec.unspecified); int popupwidth = Popupview.getmeasuredwidth (); int popupheight = Popupview.getmeasuredheight (); int[] location = new Int[2];switch (V.getid ()) {case R.id.showbtn1:v. GetlocationoNscreen (location); Popupwindow.showatlocation (V, Gravity.no_gravity, (Location[0]+v.getwidth ()/2)-POPUPWIDTH/2, location[1]- popupheight); break;case r.id.showbtn2:v.getlocationonscreen (location); Popupwindow.showatlocation (V, Gravity.no_gravity, (Location[0]+v.getwidth ()/2)-POPUPWIDTH/2, location[1]- Popupheight); break;default:break;}}}
Demo Download: http://download.csdn.net/detail/u011494050/7787359