My screen is 1080x1920. Height of green line is 1794, red line - 63 (status bar) + 84 (TitleBar) = 147, violet line - 1584. Why I dont get height of green line by adding red one to the violet one?
Violet line represents height of relative layout and I find it with this code in the onWindowFocusChanged()
:
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.myRelativeLayout);
Log.i(TAG, "Relative layout height: "+String.valueOf(relativeLayout.getHeight()));
Red line represents height of title bar and status bar and I find it with this code in the onWindowFocusChanged()
:
Rect rectangle = new Rect();
Window window = getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarHeight = rectangle.top;
int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight= contentViewTop - statusBarHeight;
Log.i(TAG, "StatusBar Height= " + statusBarHeight + " , TitleBar Height = " + titleBarHeight);
Green line suppose to represent height of whole program? and I find it with this code in the onWindowFocusChanged()
:
Display mdisp = getWindowManager().getDefaultDisplay();
Log.i(TAG, "mdisp: "+String.valueOf(mdisp));
Point mdispSize = new Point();
mdisp.getSize(mdispSize);
int maxX = mdispSize.x;
int maxY = mdispSize.y;
Log.i(TAG, "Max X, Y: "+String.valueOf(maxX)+", "+String.valueOf(maxY));
XML layout file contents:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="lt.wilkas.stackoverflowquestion.MainActivity"
android:id="@+id/myRelativeLayout">
</RelativeLayout>