Android PopupWindow usage example
The following is an example:
MainActivity. xml
Package sn. qdj. popupwindowdemo; import android. support. v7.app. actionBarActivity; import android. OS. bundle; import android. view. gravity; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. popupWindow;/*** use * @ author qingdujun **/public class MainActivity extends ActionBarActivity {@ Override protected void onCreate (Bundle s AvedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main);/*** popup. xml shows the pop-up interface Layout */View root = getLayoutInflater (). inflate (R. layout. popup, null);/*** pop-up interface * width: 400 * Height: 200 */final PopupWindow popup = new PopupWindow (root, 400,200); Button btn = (Button) findViewById (R. id. btn); Button close = (Button) findViewById (R. id. close); btn. setOnClickListener (new On ClickListener () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stub/*** pops up at a specified position. ** the first parameter specifies the PopupWindow anchor view, that is, the view attached. * The second parameter specifies the starting point as the bottom right corner of the parent * The third parameter is set to 0 pixels at the bottom of btn and shifted to the left and top. */Popup. showAtLocation (findViewById (R. id. btn), Gravity. BOTTOM, 0, 0) ;}}); close. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stub/*** close PopupWindow */popup. dismiss ();}});}}