If you want to know the size of the screen, you can use getSize.
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
If it's not an activity
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
You can write it like this. The other way is called Dispaly Metrics, which is a class related to size and density font size
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
If you want to write like this and know the width of the screen
Log.d("ApplicationTagName", "Display width in px is " + metrics.widthPixels);
You can write it like this.
© 2024 OneMinuteCode. All rights reserved.