SOURCE Address: http://download.csdn.net/detail/u014608640/7298189 do not divide the OH
Method One layout:
public void init () {ImageView popimg= (ImageView) Findviewbyid (r.id.pop_img);p Opimg.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method stublinearlayout layout = new Linea Rlayout (Showpopwindow.this); Layout.setbackgroundcolor (Color.gray); TextView TV = new TextView (showpopwindow.this); Tv.setlayoutparams (New Layoutparams (Layoutparams.wrap_content, layoutparams.wrap_content)); Tv.settext ("I ' m a pop-----------------------------!"); Tv.settextcolor (Color.White); Layout.addview (TV);//Set related properties Popwindow = new Popupwindow (layout,w,h); Sets the animation effect Popwindow.setfocusable (True);p opwindow.setoutsidetouchable (True);p opwindow.setbackgrounddrawable (new Bitmapdrawable ());p opwindow.showasdropdown (ET, 0, 1);//int[] location = new INT[2]; V.getlocationonscreen (location); Popwindow.showatlocation (V, gravity.no_gravity, Location[0], location[1]-popwindow.getheight ()); }});}
Method two custom layouts:
public void Initpopuptwindow () {ImageView popimg= (ImageView) Findviewbyid (r.id.pop_img); Popimg.setonclicklistener ( New Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method Stublayoutinflater Inflater = ( Layoutinflater) ShowPopwindow.this.getSystemService (Layout_inflater_service); View v1 = inflater.inflate (R.layout.pop_listview, NULL); EditText Et1 = (EditText) V1.findviewbyid (R.ID.ET1); W=et.getwidth (); H=et.getheight (); LOG.E ("INFO", w+ "= = =" +h);//Set related properties Popwindow = new Popupwindow (v1,w,h); Sets the animation effect Popwindow.setfocusable (True);p opwindow.setoutsidetouchable (True);p opwindow.setbackgrounddrawable (new Bitmapdrawable ());p opwindow.showasdropdown (ET, 0, 1);}});
XML code:
<relativelayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android : background= "@drawable/login_input_bg" android:gravity= "center_vertical" android:padding= "0.0dip" android:layout_margin= "15.0dip" > <textview android:id= "@+id/tx" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Frame number" Android:textcolor= "#f00" android:layout_centervertical= "true" android:padding= "10.0dip" /> <edittext android:id= "@+id/lc" android:layout_width= "Match_parent" android:layout_height= "43.0dip" android:layout_torightof= "@id/tx" android:background= "@null" /> <imageview android:id= "@+id/pop_img" android:layout_width= "Wrap_ Content "Androidoid:layout_height= "Wrap_content" android:src= "@drawable/bg_pull2" android:layout_alignparentright= "t Rue "Android:layout_centervertical=" true "android:padding=" 10.0dip "/> </relativ Elayout>
Code finished!