I have a view subclass that starts from activity subclass like that:
this.setContentView(instanceOfMyView);
In that my view subclass I want to make some work with screen size, but all people here says that it should be started like:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels;
But getWindowManager()
is the method that can be called from activity subclass only (Am I right?)
So, is it bad idea and I need to get screen size in activity and use it as parameters in view constructor or there is a way to get screen size in view subclass? Maybe, just need to somehow get a link to instance of activity in view class?
Thanks in advance.
context
object in constructor of view subclass. Thanks. – Attenuation