我的屏幕分辨率是1080x1920。绿线的高度为1794,红线是63(状态栏)+ 84(标题栏)= 147,紫色线是1584。为什么我不能通过将红线和紫线相加来获得绿线的高度?
紫色线表示相对布局的高度,我用以下代码在onWindowFocusChanged()
中找到它:RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.myRelativeLayout);
Log.i(TAG, "Relative layout height: "+String.valueOf(relativeLayout.getHeight()));
红线代表标题栏和状态栏的高度,我使用以下代码在
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);
绿色线代表整个程序的高度吗?我通过在
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布局文件内容:
<?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>