代码

View decorView = getWindow().getDecorView();View androidContent = findViewById(android.R.id.content);View androidContentFirstChild = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0);View rootView = androidContentFirstChild.getRootView();Log.i(TAG, "decorView: " + decorView.toString());Log.i(TAG, "androidContent: " + androidContent.toString());Log.i(TAG, "androidContent.getParent: " + androidContent.getParent());Log.i(TAG, "androidContentFirstChild: " + androidContentFirstChild.toString());Log.i(TAG, "rootView: " + rootView.toString());Log.i(TAG, "decoView.getChildCount: " + ((ViewGroup)decorView).getChildCount());Log.i(TAG, "androidContent.getChildCount: " + ((ViewGroup)androidContent).getChildCount());

运行截图

结论

  • decorView 与 rootView 是一个东西,都是页面的最顶层根布局,它有且仅有一个子视图
  • android.R.id.content 是一个 FrameLayout,里面才是我们在 layout 里面写的 xml 布局

Android Studio 查看布局结构

Tools ——> Layout Inspector,打开布局检查器对话框

注意,这里只有 debug 版本的 app 才可以查看布局的(第三方APP是无法查看的)

视图树

  • 最顶层是 DecorView,其下是一个 LinearLayout,包含了一个惰性布局的 ActionBar 和 FrameLayout 容器
  • 自带的 FrameLayout 的 id 固定为 android:id="@android:id/content",它的子布局才是我们在 xml 里面写的布局

更多相关文章

  1. Android文件路径
  2. Android(安卓)通过handler和message在子线程里面去更新UI
  3. Eclipse下安装Android(安卓)ADT插件问题
  4. android 內存等使用情況(转)
  5. android aapt使用小结
  6. 在android里面调用javascript代码
  7. android 模拟器上GPS的使用
  8. android 圆形的图片里面带字
  9. android中调用requestFocus()的详细过程

随机推荐

  1. Android Support Package
  2. android 获取MAC
  3. Android四种Activity的加载模式
  4. Android - 干货收集。
  5. 视频课程汇总
  6. android流式布局热门标签的实现
  7. android:cacheColorHint,android:listSel
  8. shape .xml
  9. 安装Intel HAXM为Android 模拟器加速,30秒
  10. google Android 认证测试