findViewById(R.id.content)和getRootView的区别()区别、id、findViewById、getRootView

2023-09-06 04:38:43 作者:一身英雄梦

findViewById(R.id.content)和getRootView()之间的区别是什么?不要都返回一个活动的根本看法?

What is the difference between findViewById(R.id.content) and getRootView() ? Don't both return the root view of an activity?

推荐答案

该方法的 findViewById(R.id.content) 向下搜索视图层次了ID为内容的查看(它检查自己以及)。

The method findViewById(R.id.content) searches down the view hierarchy for a View with the id content (it examines itself as well).

该方法 getRootView( ) 走了视图层次,直到达到根视图(它会检查自己以及)。

The method getRootView() walks up view hierarchy until it hits the root View (it examines itself as well).

如果您在查看具有ID 内容,它是根视图,那么这些方法会产生相同的结果,否则他们不会。

If the View you are in has the id content and it is the root view then these methods will give the same result, otherwise they won't.