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)。




  • 相关阅读:
    [洛谷P3360]偷天换日
    [BZOJ3195]奇怪的道路
    [BAOJ3631]松鼠的新家
    [BZOJ4899]记忆的轮廓
    [BZOJ3940]Censoring
    P3303 [SDOI2013]淘金
    2019.8.5 NOIP模拟测试13 反思总结【已更新完毕】
    2019.8.3 NOIP模拟测试12 反思总结【P3938 斐波那契,P3939 数颜色,P3940 分组】
    2019.8.1 NOIP模拟测试11 反思总结
    洛谷P2178 [NOI2015]品酒大会
  • 原文地址:https://www.cnblogs.com/linux007/p/5783115.html
Copyright © 2011-2022 走看看