I am trying to access some DisplayMetrics data and everything is returning zero. This is how I am initializing display metrics object:
DisplayMetrics display = new DisplayMetrics();
and when I call display.heightPixels
it's just zero. Do I need a permission or something to access DisplayMetrics
?
This is not how to use DisplayMetrics
.
This is how:
final WindowManager w = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
final Display d = w.getDefaultDisplay();
final DisplayMetrics m = new DisplayMetrics();
d.getMetrics(m);
// m now contains reliable data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With