1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > android获取软件大小 android获取屏幕大小包括状态栏和软件导航栏的大小

android获取软件大小 android获取屏幕大小包括状态栏和软件导航栏的大小

时间:2024-07-11 01:43:02

相关推荐

android获取软件大小 android获取屏幕大小包括状态栏和软件导航栏的大小

自API 17(JELLY_BEAN_MR1)以来添加了软件导航,因此我们只需要在API 17及更高版本中包含导航栏的大小.

并注意,当您获得屏幕尺寸时,它基于当前方向.

public void setScreenSize(Context context) {

int x, y, orientation = context.getResources().getConfiguration().orientation;

WindowManager wm = ((WindowManager)

context.getSystemService(Context.WINDOW_SERVICE));

Display display = wm.getDefaultDisplay();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

Point screenSize = new Point();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

display.getRealSize(screenSize);

x = screenSize.x;

y = screenSize.y;

} else {

display.getSize(screenSize);

x = screenSize.x;

y = screenSize.y;

}

} else {

x = display.getWidth();

y = display.getHeight();

}

int width = getWidth(x, y, orientation);

int height = getHeight(x, y, orientation);

}

private int getWidth(int x, int y, int orientation) {

return orientation == Configuration.ORIENTATION_PORTRAIT ? x : y;

}

private int getHeight(int x, int y, int orientation) {

return orientation == Configuration.ORIENTATION_PORTRAIT ? y : x;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。