【问题标题】:Difference between findViewById(R.id.content) and getRootView() [closed]findViewById(R.id.content) 和 getRootView() 之间的区别 [关闭]
【发布时间】:2012-05-26 22:54:51
【问题描述】:

findViewById(R.id.content) 和 getRootView() 有什么区别?不都返回活动的根视图吗?

【问题讨论】:

    标签: android view root


    【解决方案1】:

    findViewById(R.id.content) 方法在视图层次结构中向下搜索 ID 为 content 的视图(它也会检查自身)。

    方法getRootView() 遍历视图层次结构,直到它到达根视图(它也会检查自己)。

    如果您所在的视图具有 id content 并且它是根视图,那么这些方法将给出相同的结果,否则它们不会。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 2014-11-28
      • 2016-08-01
      • 2011-10-07
      • 2012-01-12
      相关资源
      最近更新 更多