I am making an app that creates tiny sprite animations that walk around your screen.

I have a main activity, with a button "start service". This starts a service, which (in `onCreate()`) creates a full-screen view and attaches it to the root window manager.

This part works perfectly. It fills the screen, and you can leave the app, and the animations will still be visible over everything.

[![initial render is fine](https://i.stack.imgur.com/jVAd2.png)](https://i.stack.imgur.com/jVAd2.png)

The problem emerges when you rotate the device.

[![view does not rotate with device](https://i.stack.imgur.com/0xk4o.png)](https://i.stack.imgur.com/0xk4o.png)

*Sprites have moved to the middle of the screen, but this is an unrelated issue; the important thing here is the dark bounding box — this box shows you the canvas I am allowed to draw into, and it needs to fill the whole screen*

The view is still portrait-mode, even though all other layouts seem to have updated correctly.

---

Part of the problem comes from how I have specified the dimensions of the view. I used flags to specify "full screen", but this did **not** set the view's `width` and `height` to match the screen's dimensions. Thus I had to set those manually at startup.

I don't know a way to update the width and height of the view once the view is created, but I feel that I need to, since the dimensions of the view determine the dimensions of the canvas.

My service creates the view like so:

```java
public class WalkerService extends Service {
    private WalkerView view;

    @Override
    public void onCreate() {
        super.onCreate();

        final WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);

        final DisplayMetrics metrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metrics);

        view = new WalkerView(this); // extends SurfaceView
        final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, // TYPE_SYSTEM_ALERT is denied in apiLevel >=19
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                PixelFormat.TRANSLUCENT
        );
        view.setFitsSystemWindows(false); // allow us to draw over status bar, navigation bar

        // here I _manually_ set the dimensions, because otherwise it defaults to a square (something like 1024x1024)
        params.width = metrics.widthPixels;
        params.height = metrics.heightPixels;

        wm.addView(view, params);
    }
}

```

I have tried listening for orientation changes, and rotating the view when that happens:

```java
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    view.setRotation(
            newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE
                    ? 90.0f
                    : 0.0f
    );
}

```

But `setRotation()` didn't seem to affect `width` and `height` of my view, nor did they change the angle at which the canvas was rendered.

---

Am I fundamentally misunderstanding how to create a full-screen overlay? How can I maintain the ability to draw over the entire screen, regardless of orientation (and even when my app is not the active app)?

Maybe it's related to the fact that I attach my view to the Window Service's window manager — perhaps this means my view has an odd parent (I could imagine that maybe the root view would not be affected by orientation, or would have no defined boundaries for children to stretch to fill).

Full source code is [public on GitHub](https://github.com/Birch-san/touhou-walk) in case I've omitted any useful information here.

`WalkerView.java` may be particularly relevant, so [here it is](https://github.com/Birch-san/touhou-walk/blob/master/app/src/main/java/uk/co/birchlabs/touhouwalk/services/walker/WalkerView.java).