1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
page.title=Hierarchy Viewer Walkthrough
meta.tags="android, performance, profiling, tools, rendering, hierarchyviewer"
page.tags="android", "performance", "profiling", "tools", "rendering", "hierarchyviewer"
page.metaDescription=Visualize your app's view hierarchy to help you simplify your layouts.
page.image=tools/performance/thumbnails/tools_hierarchy_viewer.png
page.article=true
@jd:body
<style>
.no-bullet {
list-style-type: none;
}
.padded {
padding-left: 10px;
}
</style>
<div id="tb" style="margin-left: 7px; margin-bottom: 5px;">
<h2>In this document</h2>
<ul>
<li><a href="#WhatYouNeed">Prerequisites</a></li>
<li><a href="#WorkingWithHierarchyViewer">Working with Hierarchy Viewer</a></li>
</ul>
<h2>You should also read</h2>
<ul>
<li><a href="{@docRoot}tools/performance/hierarchy-viewer/setup.html">
Device Setup for Hierarchy Viewer</a></li>
<li><a href="{@docRoot}tools/performance/hierarchy-viewer/profiling.html">
Profiling with Hierarchy Viewer</a></li>
<li><a href=
"http://developer.android.com/tools/debugging/debugging-ui.html#viewhierarchy">Hierarchy Viewer
</a></li>
<li><a href="/guide/topics/ui/overview.html#Layout">View Hierarchies</a></li>
<li><a href="{@docRoot}tools/performance/importing-legacy-apps.html">
Importing Legacy Apps into Android Studio<a></li>
<li><a href="{@docRoot}tools/device.html">Using Hardware Devices</a></li>
</ul>
</div>
<p>This walkthrough shows the basic usage and workflow for the Hierarchy Viewer tool.</p>
<p>The Hierarchy Viewer tool visualizes your app's <a href=
"http://developer.android.com/guide/topics/ui/overview.html#Layout">view hierarchy</a> and
profiles the relative rendering speed for each view.
<p>What it's good for:</p>
<ul>
<li>Simplifying your view hierarchy to reduce overdraw, and make it easier to manage.</li>
<li>Finding potential rendering performance bottlenecks related to the structure and shape of your
view hierarchy.</li>
</ul>
<h2 id="WhatYouNeed">Prerequisites</h2>
<ul>
<li>A mobile device set up to work with Hierarchy Viewer:</li>
<li style="list-style: none; display: inline">
<ol>
<li>You must have <a href=
"http://developer.android.com/tools/device.html#developer-device-options">Developer
Options</a> enabled on your mobile device. You must use a physical device to get
accurate measurements.</li>
<li>Set an {@code ANDROID_HVPROTO} environment variable on the desktop machine
that is connected to your device. For more information, see
<a href="{@docRoot}tools/performance/hierarchy-viewer/setup.html">Device Setup for Hierarchy Viewer</a>.</li>
</ol>
</li>
<li>Debuggable app code with a view hierarchy. Use your own code, or the code for the <a href=
"https://github.com/udacity/Sunshine-Version-2">Sunshine</a> sample app from the <a href=
"https://www.udacity.com/course/ud853">Android Fundamentals Udacity course</a>.</li>
</ul>
<h2 id="WorkingWithHierarchyViewer">Working with Hierarchy Viewer</h2>
<ul class="no-bullet">
<!-- this also hides bullet, by default outside box -->
<li><div style="overflow:hidden">
<ol class="padded">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image001.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 1. </strong>Starting Android Device Monitor.
</p>
</div>
<li>Connect your mobile device to your computer.</li>
<li>Open your application in Android Studio, build the source, and run it on your device.</li>
<li>From Android Studio, start the Android Device Monitor: <b>Tools > Android >
Android Device Monitor</b>.</li>
<li>Allow <b>USB Debugging</b> on your phone (if asked).</li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="6">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image005.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 2. </strong>Android Device Monitor.
</p>
</div>
<li>Figure 2 illustrates what is initially shown in the Device Monitor tool. This varies
depending on your setup.
<p>Make sure your device
and the package for your application are showing in the Devices (DDMS mode) or Windows
(Hierarchy Viewer mode) tab. You can choose <b>Window > Reset Perspective</b> to get
back to the default arrangement.</p>
<p>If the app does not appear, make sure you
followed the <a href="{@docRoot}tools/performance/hierarchy-viewer/setup.html"> device
setup instructions</a>, then start over at step 1.</p></li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="7">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image002.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 3. </strong>Changing Perspective to Hierarchy Viewer.
</p>
</div>
<li>In Android Device Monitor (ADM), in the menu bar, choose <b>Window > Open
Perspective</b>, and in the popup click <b>Hierarchy View</b>.<br>
<p>OR</p>
<p> Click the <b>Hierarchy View</b> button if it's already visible.<br>
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image003.png">
</p></li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="9">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image006.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 4. </strong>Hierarchy Viewer layout.
</p>
</div>
<li>If not already open, the Hierarchy View panes open.<br>
The example screen in Figure 4 shows an example of these panes.</li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="10">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image004.png"
alt=""
width="240px" />
<p class="img-caption">
<strong>Figure 5. </strong>Resetting the Perspective.
</p>
</div>
<li>If you see a different window arrangement, in Android Device Manager, use
<b>Window > Reset Perspective</b> to return to the default layout for this tutorial.
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="11">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image007.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 6. </strong>Populated Hierarchy Viewer.
</p>
</div>
<li>Double-click your application in the Windows tab. This populates the panes with the
view hierarchy of your application.
This display is a static representation of the complete view hierarchy defined for the
app.</li>
<li>You can adjust the sizes of the panes and ADM will preserve your
arrangement in future sessions.</li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="13">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image008.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 7. </strong>Hierarchy Viewer panes.
</p>
</div>
<li>If necessary, click the <b>Layout View</b> tab to hide the Console and show a wireframe of
your layout. The outline of the currently selected view is red. Click an outline to select
it.</li>
<li>The rest of the panes:
<ul>
<li>The <b>Tree Overview</b> in the upper right gives you a bird's-eye view of your
app's complete <a href=
"http://developer.android.com/guide/topics/ui/overview.html#Layout">View</a> <a href=
"http://developer.android.com/guide/topics/ui/overview.html#Layout">Hierarchy</a>.</li>
<li>In the <b>Tree Overview</b>, move the gray viewport rectangle to change what section of
your hierarchy shows in the <b>Tree View</b> pane (in the center).</li>
<li>In the <b>Tree View</b>, you can drag and zoom the tree using your mouse.</li>
</ul>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="15">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image009.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 7. </strong>Parts of the View node display.
</p>
</div>
<li>Click on a View node to display details. Here is an annotated close-up of a node
and its details.</li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="16">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image010.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 8. </strong>Location of View Properties tab.
</p>
</div>
<li>Click the <b>View Properties</b> tab at the top right (next to the Windows tab) to see
properties of the selected View node.</li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="17">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image011.png"
alt=""
width="400px" />
<p class="img-caption">
<strong>Figure 9. </strong>Rendering a view in a popup.
</p>
</div>
<li>Double-click a View node in the Tree View to render it in a popup window.</li>
</ol>
</div></li>
<li><div style="overflow:hidden">
<hr>
<ol class="padded" start="18">
<div class="figure" style="">
<img src="{@docRoot}images/tools/performance/hierarchy-viewer/gettingstarted_image012.png"
alt=""
width="240px" />
<p class="img-caption">
<strong>Figure 10. </strong>Node with its type and id.
</p>
</div>
<li>Nodes in the Tree View show a Type, which indicates the View class,
and an id, which is the view identifier in your code.</li>
</ol>
</div></li>
</ul>
|