Android get height and width for portrait and landscape

therefore, I wrote the following method in my work:

private void setDisplayMetrics(){ DisplayMetrics metrics = this.getResources().getDisplayMetrics(); int dh = metrics.heightPixels; int dw = metrics.widthPixels; if(dw < dh){ deviceWidth = dw; deviceHeight = dh; }else{ deviceWidth = dh; deviceHeight = dw; } System.err.println("--------------> dh : "+deviceHeight+" | dw "+deviceWidth); } 

And it works great in the sense that it gives me the full width and height of the screen with great accuracy and reliability (which is exactly what I requested).

Here is the problem. On older Android devices, the screen sizes are the same as the sizes that the application can take, and the above script helps me set the size of the elements in the application. BUT with Android ICS I have this graphic button bar at the bottom of the screen, and it messed up my strategy.

enter image description here

I would very much like that at the same moment it would be possible to get the available application sizes for a portrait view, as well as a landscape view. And these dimensions must be accurate, regardless of the presence of the strip depicted above.

Does anyone know how to achieve this?

+6
source share
2 answers
 Rect rectgle= new Rect(); Window window= getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectgle); int StatusBarHeight= rectgle.top; int contentViewTop= window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); int TitleBarHeight= contentViewTop - StatusBarHeight; Log.i("*** Jorgesys :: ", "StatusBar Height= " + StatusBarHeight + " , TitleBar Height = " + TitleBarHeight); 
0
source

From what I have read so far, you cannot get this height directly. The approach via getWindowVisibleDisplayFrame () does not work. The only promising solution I have found so far is to use a custom layout for measuring screen size, as described in http://evgeni-shafran.blogspot.de/2011/01/android-screen-size-problem.html . I am convinced that this will work, but for me it seems to be more of a problem than it's worth it.

0
source

All Articles