Android屏幕可以划分为五个区域

1. 整个屏幕

         获取方法为getRealSize或getRealMetrics,或直接从根窗口DecorView中获取         1)方法1        Point outSize = new Point();getWindowManager().getDefaultDisplay().getRealSize(outSize);int x = outSize.x;int y = outSize.y; 2)方法2DisplayMetrics outMetrics = new DisplayMetrics();getWindowManager().getDefaultDisplay().getRealMetrics(outMetrics);int widthPixel = outMetrics.widthPixels;int heightPixel = outMetrics.heightPixels; 3)方法3 DecorView   view=getWindow().getDecorView();         int width = view.getWidth();         //getWidth方法可能是过时了,不过不要紧,你输入的时候IDE会提示修改         int height = view.getHeight();      //getHeight方法可能是过时了,不过不要紧,你输入的时候IDE会提示修改

2. 应用程序区

         获取方法为getSize或getMetrics,即上述屏幕方法中去掉Real,或直接从根窗口DecorView中获取1)方法1Display defaultDisplay = getWindowManager().getDefaultDisplay();    Point point = new Point();    defaultDisplay.getSize(point);    int x = point.x;    int y = point.y;    2)方法2    Rect outSize = new Rect();    getWindowManager().getDefaultDisplay().getRectSize(outSize);    int left = outSize.left;    int top = outSize.top;    int right = outSize.right;    int bottom = outSize.bottom;    3)方法3    DisplayMetrics outMetrics = new DisplayMetrics();    getWindowManager().getDefaultDisplay().getMetrics(outMetrics);    int widthPixels = outMetrics.widthPixels;    int heightPixels = outMetrics.heightPixels;4)方法4Rect outRect = new Rect();        View view = getWindow().getDecorView();        view.getWindowVisibleDisplayFrame(outRect);        int width = outRect.width();        int height = outRect.height();

3. 应用程序区内容区

         View view2 = getWindow().findViewById(Window.ID_ANDROID_CONTENT);         int width = view2.getWidth();         int height = view2.getHeight();

4. 标题栏及状态栏

用以上获取的各区域相减即可得出

更多相关文章

  1. Android(安卓)Activity切换动画overridePendingTransition
  2. Android中使用Fragment实现标题栏(不可滑动)
  3. Android(安卓)-- 跨应用绑定service并通信
  4. [Android开发]Android(安卓)重要组件 之 Intent
  5. 【Android(安卓)开发教程】重新布局
  6. lua学习笔记 2 android调用Lua。Lua脚本中实现添加Button,并为Bu
  7. Android(安卓)容器控件
  8. Mac Android(安卓)Studio处理unable to access android sdk add-
  9. Android(安卓)onCreate方法被调用两次的解决方法

随机推荐

  1. android 图片自动切换
  2. Android应用开发相关下载资源
  3. 【30篇突击 android】源码统计 十
  4. android 入门xml布局文件--转
  5. android:windowSoftInputMode属性使用
  6. android无线调试
  7. Android在开机时自动启动一个应用程序
  8. android参考例子
  9. android manifest.xml中元素含义android
  10. Android布局属性详解