3
A
回答
6
自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;
}
相關問題
- 1. 使用軟導航欄正確檢測屏幕大小
- 2. Swift - 使用導航欄和標籤欄獲取viewController的大小
- 3. 導航欄在調整大小屏幕後消失[引導]
- 4. Twitter的導航欄更改時,屏幕大小
- 5. 什麼是iPhone屏幕頂部狀態欄的確切大小?
- 6. 調整頁面大小和導航欄的大小
- 7. 導航欄處理大於屏幕圖
- 8. MonoTouch狀態欄和EAGLView大小
- 9. 狀態欄和上海華幀大小
- 10. OpenGL ES表面大小,隱藏的Android軟件導航欄和Google Play遊戲
- 11. Android屏幕取向大小
- 12. 導航欄下面的框架大小?
- 13. 獲取屏幕大小XCode
- 14. 當導航欄縮小時修復導航欄元素的大小
- 15. 全屏沒有導航和狀態欄
- 16. Bootstrap3 - 更改導航欄大小
- 17. iOS導航欄圖標大小iPhone 6
- 18. html5/css3導航欄大小問題
- 19. 安卓導航欄大小在xml
- 20. 導航欄標題字體大小
- 21. 基於屏幕大小切換導航
- 22. OSX狀態欄圖像大小 - 可可
- 23. iPhone通話狀態欄大小?
- 24. iPhone的屏幕尺寸與狀態和導航欄?
- 25. 奇怪的小故障與消失的狀態欄/導航欄
- 26. iOS 11,狀態欄,導航欄和UIScrollview
- 27. 如何屏蔽導航欄/狀態欄android java
- 28. 固定大小的引導和導航欄中的圖像
- 29. android獲取其他屏幕方向的屏幕大小
- 30. 如何更改導航欄中titleView的大小。因爲有在的導航欄