Android9.0 推薦 獲取實際屏幕高度和寬度的方法

第一種:

    Point outSize = new Point();
    getWindowManager().getDefaultDisplay().getRealSize(outSize);
    int x = outSize.x;
    int y = outSize.y;
    Log.w(TAG, "x = " + x + ",y = " + y);
    //x = 1440,y = 2960

 

 

第二種:

    DisplayMetrics outMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getRealMetrics(outMetrics);
    int widthPixel = outMetrics.widthPixels;
    int heightPixel = outMetrics.heightPixels;
    Log.w(TAG, "widthPixel = " + widthPixel + ",heightPixel = " + heightPixel);
    //widthPixel = 1440,heightPixel = 2960

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章