zoukankan      html  css  js  c++  java
  • Android之View.getRootView

    view.getRootView的官方解释是
    Finds the topmost view in the current view hierarchy
    那这个顶层的View究竟是xml的最外层布局,还是getDecorView,抑或其他的呢?
    下面通过测试来了解getRootView的真正含义,定义xml文件如下:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/linChangeSkinRootView"
    android:layout_height="match_parent"
    android:orientation="vertical">

    //...

    <Button
    android:id="@+id/btnActCahngeSkinShowStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:padding="40dp"
    tools:text="演示台" />
    </LinearLayout>
    定义测试源码,
    lg.e("getDecorView id:" + getWindow().getDecorView().getId());
    lg.e("android.R.id.content id :" + getWindow().getDecorView().findViewById(android.R.id.content).getId());
    lg.e("getDecorView-getChildAt 0 id :" + ((ViewGroup) (getWindow().getDecorView().findViewById(android.R.id.content))).getChildAt(0).getId());

    lg.e("Act_change_skin的根布局id:" + generateView(R.id.linChangeSkinRootView).getId());
    lg.e("btnActCahngeSkinShowStyle id :" + btnActCahngeSkinShowStyle.getId());

    lg.e("Act_change_skin的getRootView id :" + generateView(R.id.linChangeSkinRootView).getRootView().getId());
    lg.e("btnActCahngeSkinShowStyle的getRootView id :" + btnActCahngeSkinShowStyle.getRootView().getId());
    打印结果:

    从运行结果可以看到,xml的根布局应该对应((ViewGroup)getWindow().getDecorView().findViewById(android.R.id.content))).getChildAt(0)。




  • 相关阅读:
    php 不依赖数据实现删除图片,核心代码
    php插入htm htm插入php的变量
    php 删除指定文件 glob,unlink
    glob函数 循环遍历子目录下的文件
    对函数及递归的通俗理解
    glob 遍历函数
    修改 ueditor1_4_3-utf8-php 它的图片上传地址
    thinkphp 自动跟新时间
    用Hadoop构建电影推荐系统
    Hive导入10G数据的测试
  • 原文地址:https://www.cnblogs.com/linux007/p/5783115.html
Copyright © 2011-2022 走看看