WindowManager 浮动 window 通过屏幕边框
WindowManager floating window through screen borders
我对由 windowmanager 提供支持的浮动 window 有疑问。它停在屏幕边界处,但我希望它通过。
void startF(int x, int y) {
removePopup();
DisplayMetrics displayMetrics = new DisplayMetrics();
mainActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
screenHeight = displayMetrics.heightPixels;
screenWidth = displayMetrics.widthPixels ;
gestureDetector = new GestureDetector(mainActivity, new SingleTap());
windowManager = (WindowManager) mainActivity.getSystemService(Context.WINDOW_SERVICE);
linearLayout = new LinearLayout(mainActivity);
linearLayout.setBackgroundColor(mainActivity.getResources().getColor(R.color.red));
final WindowManager.LayoutParams WMparams = new WindowManager.LayoutParams(100,100,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSPARENT);
//WMparams.gravity = Gravity.CENTER | Gravity.END;
WMparams.x = x;
WMparams.y = y;
windowManager.addView(linearLayout, WMparams);
如图
将以下标志添加到 window:FLAG_LAYOUT_NO_LIMITS
Window flag: allow window to extend outside of the screen.
我对由 windowmanager 提供支持的浮动 window 有疑问。它停在屏幕边界处,但我希望它通过。
void startF(int x, int y) {
removePopup();
DisplayMetrics displayMetrics = new DisplayMetrics();
mainActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
screenHeight = displayMetrics.heightPixels;
screenWidth = displayMetrics.widthPixels ;
gestureDetector = new GestureDetector(mainActivity, new SingleTap());
windowManager = (WindowManager) mainActivity.getSystemService(Context.WINDOW_SERVICE);
linearLayout = new LinearLayout(mainActivity);
linearLayout.setBackgroundColor(mainActivity.getResources().getColor(R.color.red));
final WindowManager.LayoutParams WMparams = new WindowManager.LayoutParams(100,100,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSPARENT);
//WMparams.gravity = Gravity.CENTER | Gravity.END;
WMparams.x = x;
WMparams.y = y;
windowManager.addView(linearLayout, WMparams);
如图
将以下标志添加到 window:FLAG_LAYOUT_NO_LIMITS
Window flag: allow window to extend outside of the screen.