evi*_*one 59
如果您想要显示尺寸(以像素为单位),可以使用以下代码:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Run Code Online (Sandbox Code Playgroud)
然后,您可以添加比较高度的条件以满足您的需求.
以英寸来算:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(dm.widthPixels/dm.xdpi,2);
double y = Math.pow(dm.heightPixels/dm.ydpi,2);
double screenInches = Math.sqrt(x+y);
Log.d("debug","Screen inches : " + screenInches);
Run Code Online (Sandbox Code Playgroud)
ina*_*ruk 20
从活动内部:
int width = getWindowManager().getDefaultDisplay().getWidth();
int height = getWindowManager().getDefaultDisplay().getHeight();
Run Code Online (Sandbox Code Playgroud)
或者如果你只有Context对象:
WindowManager windowManager = (WindowManager)mContext.getSystemService(WINDOW_SERVICE);
int width = windowManager.getDefaultDisplay().getWidth();
int height = windowManager.getDefaultDisplay().getHeight()
Run Code Online (Sandbox Code Playgroud)
更新.如何检测您的应用程序在大屏幕上运行:
//Android Level 9 and up:
Configuration config = getResources().getConfiguration();
if((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_XLARGE)
{
//xlarge screen
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60634 次 |
| 最近记录: |