Hey
Hey

Reputation: 95

WindowManager floating window through screen borders

I have a problem with floating window powered by windowmanager. It stops at screen border but i want it to go through.

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);

As in the picture

enter image description here

Upvotes: 1

Views: 432

Answers (1)

RobCo
RobCo

Reputation: 6495

Add the following flag to the window: FLAG_LAYOUT_NO_LIMITS

Window flag: allow window to extend outside of the screen.

Upvotes: 1

Related Questions