in the MainActivity class the following code works fine to get screen size
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
I wanted to get the width and height in my onDraw
method so if the user rotates the device the method would see the new values
so I copied the code into my onDraw
method.
I get a error saying:
getWindowManager() is undefined
I'm assuming this because the onDraw method is in a different class si it does not have that method.
Is there a way to get the screen size in the onDraw method?