Android has three types of Windows
Application Window: contains the windows created by all applications and the Windows displayed by the system before the Application starts.
Subwindow: for example, a custom application dialog box or input Window, the subwindow must be attached to an application Window (set the same token ).
System Window: the System design is not attached to any application Window, such as the Status Bar, Navigation Bar, and Wallpaper ), phone, KeyGuard, Toast, volume adjustment, and mouse cursor.
Popupwindow belongs to the sub window, so a view must be attached.
There are two main methods:
ShowAtLocation (View parent, int gravity, int x, int y)
Show popupwindow in special position
ShowAsDropDown (View anchor, int xoff, int yoff)
The position of x offset and y offset in the lower left corner of view anchor
Public void on_effect (final View v) {/* data.src_bmp extends myview.bmp; Intent intent = new Intent (drowview. this, BMP effect. class); startActivity (intent); * // The preceding linear layout disappears Log. e ("on_effect", "ing"); pop_num = 0; // relayout2.setVisibility (View. GONE); // relayout. setVisibility (View. VISIBLE); show = true; int [] location = new int [2]; v. getLocationOnScreen (location); Log. e ("" + location [0], "" + location [1]); mypopwindow. showAtLocation (v, Gravity. BOTTOM | Gravity. CENTER_HORIZONTAL, 0, 0 );}
Implement floating and listening for Ontouch events in the Android system Window
public void on_show(final View v){//showpop=(LinearLayout) findViewById(R.id.linearLayoutpop1);//Log.e("show", "ing");if(pop_show_flag==false){showpop.setVisibility(View.VISIBLE);leftpop.invalidate();windowManager.removeViewImmediate(leftpop);//leftpop.setOnTouchListener(l)leftpop=getLayoutInflater().inflate(R.layout.leftpopwindow2, null);leftpop.setOnTouchListener(mylistener);windowManager.addView(leftpop, windowManagerParams);windowManager.updateViewLayout(leftpop,windowManagerParams);pop_show_flag=true;Log.e("show", "flase");}else{windowManager.removeViewImmediate(leftpop);leftpop=getLayoutInflater().inflate(R.layout.leftpopwindow,null);leftpop.setOnTouchListener(mylistener);windowManager.addView(leftpop, windowManagerParams);windowManager.updateViewLayout(leftpop,windowManagerParams);pop_show_flag=false;Log.e("show", "true");}}
Window parameter initialization
windowManager=this.getWindowManager();windowManagerParams=new WindowManager.LayoutParams();windowManagerParams.format = PixelFormat.RGBA_8888;; windowManagerParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION;windowManagerParams.flags=android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;//|android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;//windowManagerParams.flags=android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;windowManagerParams.gravity=Gravity.LEFT|Gravity.CENTER_VERTICAL;
The format is transparent.
Type can be used to test TYPE_PHONE in the system window, or others. The larger the window value, the more on it,
Flag indicates the view parameters, whether the view can be touched or focused.
Grvavity indicates the position of the view.
Leftpop. setOnTouchListener (mylistener); set the ontouch listener in this, you can manually call the following onTouch
Mylistener = new OnTouchListener () {@ Overridepublic boolean onTouch (View v, MotionEvent event) {// TODO Auto-generated method stubLog. e ("top", "ing"); // v. my_drow_view.onTouchEvent (event); // call onTouchreturn true here ;}};
Popupwindow: click a location other than view to disappear
popupWindow.setFocusable(true);
In this way, popupWindow gets the focus, and the following content is not active.
However, you cannot click the other part of the screen to make it disappear, and the Return key does not work.
In this case, set BackgroundDrawable for the popupWindow. If you have defined the layout and want to destroy the style, you only need to set an empty Drawable.
popupWindow.setBackgroundDrawable(new PaintDrawable());