簡體   English   中英

我怎樣才能獲得android Honeycomb系統的屏幕寬度和高度?

[英]How can I get android Honeycomb system's screen width and height?

我的代碼:

Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);

System.out.println("screen width:"+displayMetrics.widthPixels);
System.out.println("screen heigth:"+displayMetrics.heightPixels);

當我在android Honeycomb系統中運行這個程序時,輸出是800和1232,但設備的屏幕是800_1280,我可以得到它嗎? 謝謝。

這段代碼適合我(如果你不介意使用未記錄的方法):

Display d = getWindowManager().getDefaultDisplay();
int width, height;

Method mGetRawH;
Method mGetRawW;
try {
    mGetRawH = Display.class.getMethod("getRawWidth");
    mGetRawW = Display.class.getMethod("getRawHeight");
    width = (Integer) mGetRawW.invoke(d);
    height = (Integer) mGetRawH.invoke(d);
} catch (NoSuchMethodException e) {
    e.printStackTrace();
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (InvocationTargetException e) {
    e.printStackTrace();
}

//You should care about orientation here
int o = getResources().getConfiguration().orientation;
if (o == Configuration.ORIENTATION_PORTRAIT) {
    if (width > height) {
        int tmp = width;
        width = height;
        height = tmp;
    }
} else if (o == Configuration.ORIENTATION_LANDSCAPE) {
    if (width < height) {
        int tmp = width;
        width = height;
        height = tmp;
    }
}

Log.d("d", "w=" + width + " h=" + height);

1280 x 752 - 風景800 x 1232 - 肖像

這個48像素用於Andriod默認通知欄...

設備全屏width=800 and height=1280 (including status bar, title bar) 如果運行代碼以獲得顯示大小,系統將不包括狀態欄高度和標題欄高度,因此您將獲得height as 1232 (1280-(status bar height + title bar height))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM