android - Hierarchyviewer 中的测量、布局和绘制时间(更好)解释

标签 android hierarchyviewer

我正在尝试理解层次结构 View 。

所以我正在阅读developer.android.com三个点的含义:

Green: For this part of the render time, this View is in the faster 50% of all the View objects in the tree. For example, a green dot for the measure time means that this View has a faster measure time than 50% of the View objects in the tree.

Yellow: For this part of the render time, this View is in the slower 50% of all the View objects in the tree. For example, a yellow dot for the layout time means that this View has a slower layout time than 50% of the View objects in the tree.

Red: For this part of the render time, this View is the slowest one in the tree. For example, a red dot for the draw time means that this View takes the most time to draw of all the View objects in the tree.

如果我没记错的话,这是否意味着最多应该有 3 个带有红点的 View (每个类别中最慢的 View :测量、布局、绘制),然后一半的 View 是黄色的,一半是黄色的绿色。

首先,我看到超过 3 个带有红点的 View ,但我不明白为什么。

其次,考虑到这些是相对值,我看不出这些值如何帮助提高性能。总会有一半的观看速度比另一半快。

查看 TreeView 时,我看到visibility gone 的 View 绘制时间很短。不应该完全忽略 GONE View 吗?

最佳答案

If I'm not mistaken, doesn't that mean that there should always be at most 3 views with red dots

你的逻辑很好,但是文档一定不能说树,而是在一个节点。您用来获取这 3 个点的层次结构查看器的 tool4s 函数是 Profile Node,这将开始分析从所选节点(树的任意根)到结束的树树。

每个 View 中包含多个 View 的 ViewGroup ( layouts are based on ViewGroup) 都会有点。在相反的情况下没有点。

所以只在节点级别进行比较,而不是对所有树进行比较,这就是为什么你可以为所有树获得三个以上的红点(一个用于测量,一个用于布局,一个用于绘制),但不适用于节点。

Second, I don't see how these values can help improve performance considering that these are relative values. There will always be half of the views faster than the other half.

圆点可帮助您了解 View 组中的哪个 View 测量/布局/绘制最慢。为避免屏幕卡住,操作的总时间必须低于 16.6 毫秒(android 应保持每秒 60 帧的帧率)。

红点只会提示您应该分析哪个 View ,但这并不意味着 View 未优化,尤其是对于具有许多子级的复杂层次结构。

此外,如果您必须构建自定义 View ,层次结构查看器可以帮助您了解您是否正确地进行了快速渲染。

I am seeing views with visibility gone that have a small draw time. Shouldn't GONE views be completely ignored?

可见性设置为 GONEView 将不会通过 onMeasureonLayoutonDraw。如果您扩展像 TextView 这样的小部件并使用 Log.d 覆盖这些方法以了解发生了什么,您可以轻松地尝试它。

但我想绘制时间到了,因为将创建 View ,然后附加到窗口并最终更改其可见性。

带有 TextView 的示例。第一步,对象是通过 java 构造函数 public Text(Context context, AttributeSet attrs){...} ) 创建的,然后将使用 protected void onAttachedToWindow 执行附加窗口的调用() {...} 并且可见性随 protected void onWindowVisibilityChanged(int visibility) {}

发生变化

现在,如果您想调试更多的用户界面,请尝试使用具有选项 Debug GPU Overdraw 的手机进入开发者选项(并非所有手机都有)或使用模拟器。然后你可以看到应用程序在哪里 overdraw ,然后优化你的界面。 Debug GPU Overdraw walkthrough

关于android - Hierarchyviewer 中的测量、布局和绘制时间(更好)解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32399057/

相关文章:

javascript - 如何在 1 次后停止 gif react-native?

android - BubblePopupHelper 填充 Android 调试日志

android-studio - uiautomatorviewer 是否取代了 Android 设备监视器中的 HierarchyViewer?

android - hierarchyviewer 不工作

android - Android Studio 是否有 Hierarchy Viewer 或 Layout Inspector?

Android card.io sdk 显示此设备无法使用相机读取卡号

java - ScrollView 没有完全向下滚动

android - 仅适用于我的 android 客户端的网站 API

java - 如何使 "Hierarchy Viewer"在真实设备中工作?

android - 如何将android工具目录添加到windows 7路径?