1 Private voidShowpopupwindow (View v) {2 3 //a custom layout that is displayed as content4View Contentview = Layoutinflater.from ( This). Inflate (R.layout.view_popup_chginfo_details,NULL);5 6 //Findviewbyid7 Initpopview (contentview);8 9Popupwindow =NewPopupwindow (Contentview,TenViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,true); One APopupwindow.setwidth (280); -Popupwindow.settouchable (true); - thePopupwindow.settouchinterceptor (NewView.ontouchlistener () { - @Override - Public BooleanOnTouch (View arg0, motionevent arg1) { - //TODO auto-generated Method Stub + return false; - //If this returns true, the touch event will be intercepted + //Popupwindow Ontouchevent is not invoked after interception, so clicking on the external area cannot be dismiss A } at }); - -Colordrawable DW =NewColordrawable (0000000000); - //If you do not set the background of the Popupwindow, you cannot dismiss the frame either by tapping the external area or the back button - popupwindow.setbackgrounddrawable (DW); - in //set the parameters and show them again. -Popupwindow.showasdropdown (v,10,0); to +}
1.showAtLocation
Example:showatlocation (Findviewbyid (r.id.search_ib), Gravity.top | gravity.right,10, ten);
The first parameter: This view is to be able to get the only indicator of the window (that is, as long as you can get to the window indicator, what is the view
Control), it should be indicated that this PW added to which window, to control the presence of the location of PW has no effect;
Second parameter: Keep in mind that the screen origin is the upper-left corner of the screen. Gravity.top | Gravity.right refers to the upper right corner of the screen,
Then the center point coordinates of PW are (screen width, 0). PW is the default in the middle of the screen, that is, Gravity.left represents the center point of PW
Coordinates are (0,1/2 screen height);
The third to fourth parameter: The offset is the second argument as the Datum point, and the direction of the offset is related to the second parameter. Gravity.top | Gravity.right, in the upper right corner of the screen as the Origin point
, PW offsets 10 pixels from the negative direction of the x-axis, and offsets 10 pixels in the positive direction of the y-axis; gravity.bottom| Gravity.left,
In the lower left corner of the screen, PW offsets 10 pixels from the positive direction of the x-axis and 10 pixels in the positive direction of the y-axis.
Note: This offset can be positive or negative. No matter how large the offset, PW will not run out of the screen. The exact direction of the shaft.
Offset, in relation to the second parameter, for Gravity.center, the offset negative indicates the negative direction to the axis, positive direction of the Axis
2.showAsDropDown
For example: Showasdropdown (MainActivity.this.findViewById (R.id.logo_iv), 100,0),
The lower left corner of the R.id.logo_iv is the origin, the positive direction of the x-axis is offset by 100 pixels, and the y-axis direction is 0 pixels.
Note: This offset can be positive or negative. No matter how large the offset, PW will not run out of the screen.
Use of Android Popupwindow