Droid screen resolution is not 480x854?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Droid screen resolution is not 480x854?

Postby Jorenm » Thu Dec 17, 2009 11:25 pm

Code: Select all
      WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
       Display d = wm.getDefaultDisplay();
       int height = d.getHeight();
       int width = d.getWidth();
       Log.v(TAG, Integer.toString(width));
       Log.v(TAG,  Integer.toString(height));


Result is : 320 x 569

What the heck is going on?
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Top

Re: Droid screen resolution is not 480x854?

Postby marbalon » Wed Dec 23, 2009 11:24 am

Jorenm wrote:
Code: Select all
      WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
       Display d = wm.getDefaultDisplay();
       int height = d.getHeight();
       int width = d.getWidth();
       Log.v(TAG, Integer.toString(width));
       Log.v(TAG,  Integer.toString(height));


Result is : 320 x 569

What the heck is going on?


Try in this way...
Code: Select all
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
width = dm.widthPixels * dm.scaledDensity; //(320*1,5)=480
height = dm.heightPixels * dm.scaledDensity; //(569*1,5)=853,5 (almost 854 ;) )

Hope this helps.
Marcin.
marbalon
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Aug 25, 2009 11:29 am

Postby Jorenm » Wed Dec 23, 2009 8:03 pm

Hmm. What is going on there exactly? Does it by default not let you work with actual pixel resolutions?
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Postby rageman » Sat Dec 26, 2009 11:04 am

Yes that is the default behaivior if the android:minSdkVersion and targetSdkVersion is less then 4.
If this is the case android tries to run the application in Medium DPI in order to be able to run older apps decently on large screens without any changes.
You can easely fix this by adding targetSdkVersion=4 in the manifest file.
rageman
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Dec 26, 2009 10:57 am

Postby glr » Sat Dec 26, 2009 8:09 pm

Are you sure that you don't need to Override the onDraw method or onSizeChanged method in order to get the correct screensize...? From what I understand you will not get the correct numbers until during the layout stage.

I am just throwing that out there.
glr
Freshman
Freshman
 
Posts: 9
Joined: Sat Nov 28, 2009 9:09 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests