如何在Android XML布局中获取状态栏高度?

如何在Android XML布局中获取状态栏高度?,android,react-native,splash-screen,Android,React Native,Splash Screen,我有两个相同的屏幕,屏幕中央有一个徽标 但是,一个屏幕考虑了状态栏的高度,而另一个屏幕没有,因此徽标的位置在两个屏幕之间不匹配 这是xml上的代码 屏幕1 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/blue" />

我有两个相同的屏幕,屏幕中央有一个徽标

但是,一个屏幕考虑了状态栏的高度,而另一个屏幕没有,因此徽标的位置在两个屏幕之间不匹配

这是xml上的代码

屏幕1

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/blue" />
    <item
        android:height="200dp"
        android:width="200dp"
        android:gravity="center"
        android:drawable="@mipmap/ic_launcher_foreground">
    </item>
</layer-list>

屏幕2

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue"
    android:gravity="center">

    <ImageView
        android:layout_height="200dp"
        android:layout_width="200dp"
        android:layout_marginBottom = "39dp"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher_foreground"/>

</LinearLayout>

我使用galaxy s10,它的状态栏高度为39dp。 现在我可以手动设置边距39以匹配徽标的位置(如上面的代码),但这仅适用于一个特定设备(即s10)。我需要为不同的移动设备动态设置余量

我该怎么做?为什么一个屏幕集成了状态栏的高度,而另一个没有


另外,这是一个react本地项目

哦,对不起,我错了,java文件中使用了这个方法。你找到答案了吗?我也在寻找同样的方法。哦,对不起,我错了,java文件中使用了这个方法。你找到答案了吗?我也在找同样的。