What is the equivalent form of class java.awt.Dimension
for android?
You can choose one of these options:
android.util.Size
(since API 21). It has getWidth()
and getHeight()
, but note it's immutable, meaning that once created you can't modify it (only create new, updated instances).
android.graphics.Rect
. It has getWidth()
and getHeight()
but they're based on internal left
, top
, right
, bottom
and may seem bloated with all its extra variables and utility methods.
android.graphics.Point
which is a plain container, but the name is not right and it's main members are called x
and y
which isn't ideal for sizing. However, this seems to be the class to use/abuse when getting display width and height from the Android framework itself as seen here:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
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