开发者

android problem in getting the screen resolution size

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
Log.e("FirstImage", "Width = "+width+"Height = "+height);

The above wa开发者_Go百科s the code I have used to display the screen size.. but the problem is I am getting width=320 and height=569. But I am using motorola milestone with screen size 480x854

How can I get the correct size?


http://realmike.org/blog/2010/12/21/multiple-screen-sizes-with-processing-for-android/

above link has excellent resource that tells about the screen resolution and how to get the real screen resolution etc....read fully you will come to know about the reality


If you don't set the supporting of larger screens, you'll get this i'm afraid, because the screen is pretending to be smaller to be able to show the app (that is supposed to not support your big screen).

If you add this to your manifest it will show the correct values

     <supports-screens 
        android:largeScreens="true" 
        android:smallScreens="true" 
        android:normalScreens="true" 
     /> 

you might even want to play with the

 android:anyDensity

attribute, but I don't think it is needed for your current problem.


try this

WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display d = wm.getDefaultDisplay();
int height = d.getHeight();


The <supports-screens> tag should definitely work. See

http://developer.android.com/guide/topics/manifest/supports-screens-element.html

An important question is, why don't you trust the scaled dimensions you're getting from the DisplayMetrics? If you were to do something like

canvas.drawRect(new Rect(0,0,width,height), new Paint());

Your rectangle would certainly fill the screen. There's a scaling happening, but maybe you don't care.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜