如果你想第一时间收到类似的文章 点击上面↑「爱开发」关注我们!
对于这样的布局,我们可以用GridView控件或RecyclerView控件来实现,提倡用RecyclerView控件来实现了。一屏显示16个应用,这样就需要和屏幕的知识点联系上了。 1、获取顶部status bar 高度
/** * 获取顶部status bar 高度 */ private int getStatusBarHeight() { Resources resources = mActivity.getResources(); int resourceId = resources.getIdentifier("status_bar_height", "dimen","android"); int height = resources.getDimensionPixelSize(resourceId); Log.v("dbw", "Status height:" height); return height; } 2、获取底部 navigation bar 高度
private int getNavigationBarHeight() { Resources resources = mActivity.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android"); int height = resources.getDimensionPixelSize(resourceId); Log.v("dbw", "Navi height:" height); return height; } 这里对于底部,我们得花点心思,华为手机自带下面有底部导航。我们要先通过判断设备是否有返回键、菜单键(不是虚拟键,是手机屏幕外的按键)来确定是否有navigation bar (已验证可行)。主要是KeyEvent.KEYCODE_BACK和hasPermanentMenuKey
@SuppressLint("NewApi") public static boolean checkDeviceHasNavigationBar(Context activity) { boolean hasMenuKey = ViewConfiguration.get(activity) .hasPermanentMenuKey(); boolean hasBackKey = KeyCharacterMap .deviceHasKey(KeyEvent.KEYCODE_BACK); if (!hasMenuKey |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|