android - 获取活动在分屏中的位置
问题描述
如何在分屏中获取活动位置?
我需要检查活动是否在屏幕顶部以显示或隐藏状态栏填充。当设备为横向时,两个应用程序都有状态栏。
我怎样才能检查这个?
解决方案
使用 w 的绝对位置View
。您可以检查位置(从上到下)。从您的代码中,找到主要内容View
,然后。
public static boolean isOnTopScreen(@NonNull View content) {
final int[] location = new int[2];
content.getLocationOnScreen(location);
return location[1] <
(getScreenHeight() / 2);
}
public static int getScreenHeight() {
return Resources.getSystem()
.getDisplayMetrics().heightPixels;
}
推荐阅读
- python - 如何将 bash curl 请求转换为 python
- sql - 为同一列返回具有不同特定数据的行或使用 POSTGRESQL 返回 0 行
- macos - 如何摆脱 Metal MTLTexture 中的 alpha 通道?
- ansible - 从 VMWare 获取事实的 Ansible Playbook
- sql-server - 延迟存储过程执行
- javascript - Particles.js 背景未调整
- algorithm - 反馈顶点集
- python - 从数组python中找到每个点之间的长度
- c# - GroupBy 两个变量,其中一个来自嵌套列表
- node.js - Composer 2.0 机器人的自定义操作未执行