I made an application with a dynamic layout for different screen sizes.
It also worked for all screen sizes except of 320×240 screens.
I used the same code to get the width and height for all and it also return the correct value but the it does not return the correct value for manually create emulator means 320×240 and 240×400.
I used the following code:
DisplayMetrics metrics = new DisplayMetrics();
WindowManager manager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
manager.getDefaultDisplay().getMetrics(metrics);
int width=metrics.widthPixels;
int height=metrics.heightPixels;
I am late..but would like to share 🙂
Please try below code snippets: