Android's Popwindow operation

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.