Karthik
Karthik

Reputation: 5033

Not able to get the correct size of the screen in android 2.3?

I am trying to get the size of the screen. The size I have set for emulator is 540 x 960 but what I am getting is 320 x 480. Any suggestions on it to get the right size. Here is the code;

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
width = dm.widthPixels;
height = dm.heightPixels;

Upvotes: 2

Views: 2404

Answers (2)

Hardik4560
Hardik4560

Reputation: 3220

try this one:

int height = getWindowManager().getDefaultDisplay().getHeight();
int width = getWindowManager().getDefaultDisplay().getWidth();

Upvotes: 1

Carnal
Carnal

Reputation: 22064

Try this:

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

Upvotes: 7

Related Questions