android - 如何在 Android XML 布局中获取状态栏高度?
问题描述
我有两个相同的屏幕,屏幕中央有一个徽标。
但是,一个屏幕考虑了状态栏高度,而另一个没有考虑,因此徽标的位置在两者之间不匹配。
这是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)。我需要为不同的移动设备动态设置边距。
我该怎么做呢?为什么一个屏幕集成了状态栏高度而另一个没有?
Ps 这是一个 react-native 项目。
解决方案
推荐阅读
- python - BeautifulSoup 让 'span' 内容彼此相邻
- javascript - Javascript数组值不能重新排序
- c# - 标准用户在 Windows Server 2012 R2 上的 ExitWindowsEx 行为差异
- r - Titanic - 循环获取名称
- prolog - 如何检查 Prolog 中的空参数?
- python - pandas:为什么在这种情况下滚动不起作用,我正在做一个分组,然后滚动`n`m聚合?
- jquery - 计时器到期后禁用按钮
- angular - Angular 8 中的链式 POST 调用
- python - 如何在Python列表中对列表中的字符串执行方法
- amazon-web-services - 标记创建 AWS IAM 政策