0

我说的是设备分辨率而不是屏幕尺寸。

我看到了很多以前的问题的答案,比如 320 x480,我认为这是屏幕尺寸。如果我错了,请纠正我。

例如,三星 Galaxy Note 分辨率为 1280 x 800 像素。

我如何在java编程中获得这个值?

4

4 回答 4

3

尝试这个

Display display = getWindowManager().getDefaultDisplay(); 
            int width = display.getWidth();  // deprecated
            int height = display.getHeight();  // deprecated
            Log.d("hai",width+"");
            Log.d("hai",height+"");
            DisplayMetrics dm = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(dm);
            double x = Math.pow(width/dm.xdpi,2);
            double y = Math.pow(height/dm.ydpi,2);
            double screenInches = Math.sqrt(x+y);
            Log.d("hai","Screen inches : " + screenInches+"");
于 2012-05-24T03:26:19.123 回答
0

800x1280px 是根据http://www.phonegg.com/compare/27/Samsung-I9100-Galaxy-S-II-vs-Samsung-Galaxy-Note.html的分辨率

这个问题应该告诉您如何获得解决方案。 以像素为单位获取屏幕尺寸

于 2012-05-24T03:24:31.917 回答
0

使用这个简单的代码来获得分辨率。

Display display = getWindowManager().getDefaultDisplay(); 
        int  width = display.getWidth();
        int height= display.getHeight();
        TextView w=(TextView)findViewById(R.id.textView2);
        w.setText(""+width);
        TextView h=(TextView)findViewById(R.id.textView4);
        h.setText(""+height);
于 2012-05-24T04:03:53.400 回答
0

试试这个例子,了解如何获取有关设备显示的信息。

于 2012-05-24T04:48:17.087 回答