简体   繁体   English

屏幕宽度和高度Android

[英]Screen Width and Height Android

what minimum-sdk and target-sdk to be set so that we can check for the android version and use the either getSizez() or getWidth() and getHeight() depending on the version of android. 要设置的minimum-sdk和target-sdk,以便我们可以检查Android版本,并根据Android版本使用getSizez()getWidth()getHeight() my current minimum sdk is 8 and target is 13 . 我目前的最低SDK为8 ,目标为13

what I am doing currently is 我目前正在做的是

    Display display=getWindowManager().getDefaultDisplay();

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD) 
    {
        width=display.getWidth();
        height=display.getHeight();
        // only for android older than gingerbread
    }
    else
    {
        display.getSize(point);
        width=point.x;
        height=point.y;
        Log.I("Width",Integer.toString(width));
        Log.I("Height",Integer.toString(height));
    }

but it is giving error over display.getSize(point) The error it gives is 但是它在display.getSize(point)上给出了错误。

The method getSize(Point) is undefined for the type Display..

Any kind of help would be really appreciated. 任何形式的帮助将非常感激。

When checking on the developer.android.com site, it says that the display.getSize(point) is only valid for android version 13 and above so I would change your initial if statement from 在developer.android.com网站上检查时,它说display.getSize(point)仅对android 13及更高版本有效,因此我将从

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD) 如果(Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD)

to

if (Build.VERSION.SDK_INT < 13) 如果(Build.VERSION.SDK_INT <13)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM