Features of 1.PopupWindow
Borrowing Google's official statement:
A Popup window that can is used to the display an arbitrary view. The popup window is a floating container this appears on topof the current activity. "
Other words. Popupwindow is a suspended container above the activity. It is able to display casual views of the view, very domineering look.
Here's how it's used.
2. Initialize some features of Popupwindow
Example:
Popupwindow Popupwindow = new Popupwindow (Getapplicationcontext ());p Opupwindow.setcontentview (ContentView);// Ability to set arbitrary viewpopupwindow.setwidth (layoutparams.wrap_content);//Set width popupwindow.setheight (layoutparams.wrap_ CONTENT);//Height Popupwindow.setanimationstyle (r.anim.abc_fade_in);//Display animation popupwindow.setfocusable (TRUE);// Set whether to get focus
among them, Contentview is the view you want to display. This view, you can use layoutinflater. from (context) . inflate mapping the corresponding XML file
3.PopupWindow Display and hide
The method shown:
public void Showatlocation (View parent, int gravity, int x, int. y) Added in API level 1Display the content View in a popup Window at the specified location. If the popup window cannot fit on screen, it'll be clipped. See Windowmanager.layoutparams For more information in how gravity and the x and Y parameters is related. Specifying a gravity of no_gravity is similar to specifying Gravity.left | Gravity.TOP.Parametersparenta Parent view to get the Getwindowtoken () token fromgravitythe Gravity which controls the Plac Ement of the Popup windowxthe popup ' s x location offsetythe popup's Y location offset
Popupwindow. showatlocation (Contentview, Gravity. CENTER , 0, 0) ;//Set Center
Popupwindow. showatlocation (Contentview, Gravity. no_gravity , x , y) ;//Displays the position of the form with (x, y) as the upper-left corner
Hide:
if (Popupwindow! = null&& popupwindow.isshowing ()) {Popupwindow.dismiss ();p Opupwindow = null;}
Related: Note that when calculating the location of the view:
Android provides some ways to get the view position on the screen.
1). Getlocationonscreen, calculates the x, Y value of the view in the global coordinate system, gets the absolute coordinates within the current screen (the value is counted from the top of the screen. Contains the height of the notification bar).
2). Getlocationinwindow, calculates the x, Y value of the view in the coordinates of the widnow where it resides.
3) GetLeft, GetTop, Getbottom, GetRight, this group is to get the coordinates relative to its father's layout.
Related: Popupwindow animation: http://blog.csdn.net/wl455624651/article/details/7798879
Many other exchanges, Android Development Alliance QQ Group: 272209595
Android:popupwindow usage Scenarios and considerations