You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/html/training/improving-layouts/optimizing-layout.jd
+23-22Lines changed: 23 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ next.link=reusing-layouts.html
18
18
<ol>
19
19
<li><a href="#Inspect">Inspect Your Layout</a></li>
20
20
<li><a href="#Revise">Revise Your Layout</a></li>
21
-
<li><a href="#Layoutopt">Use Layoutopt</a></li>
21
+
<li><a href="#Lint">Use Lint</a></li>
22
22
</ol>
23
23
24
24
<!-- other docs (NOT javadocs) -->
@@ -44,7 +44,7 @@ is inflated repeatedly, such as when used in a {@link android.widget.ListView} o
44
44
android.widget.GridView}.</p>
45
45
46
46
<p>In this lesson you'll learn to use <a
47
-
href="{@docRoot}guide/developing/tools/hierarchy-viewer.html">Heirachy Viewer</a> and <a
47
+
href="{@docRoot}guide/developing/tools/hierarchy-viewer.html">Hierarchy Viewer</a> and <a
48
48
href="{@docRoot}guide/developing/tools/layoutopt.html">Layoutopt</a> to examine and optimize your
49
49
layout.</p>
50
50
@@ -53,7 +53,7 @@ layout.</p>
53
53
<h2 id="Inspect">Inspect Your Layout</h2>
54
54
55
55
<p>The Android SDK tools include a tool called <a
56
-
href="{@docRoot}guide/developing/tools/hierarchy-viewer.html">Heirachy Viewer</a> that allows
56
+
href="{@docRoot}guide/developing/tools/hierarchy-viewer.html">Hierarchy Viewer</a> that allows
57
57
you to analyze your layout while your application is running. Using this tool helps you discover
58
58
bottlenecks in the layout performance.</p>
59
59
@@ -130,27 +130,28 @@ example of how each layout has appropriate uses and you should carefully conside
130
130
layout weight is necessary.</p>
131
131
132
132
133
-
<h2 id="Layoutopt">Use Layoutopt</h2>
133
+
<h2 id="Lint">Use Lint</h2>
134
+
135
+
<p>It is always good practice to run the <a href="http://tools.android.com/tips/lint">Lint</a> tool on your layout files to search for possible view hierarchy optimizations. Lint has replaced the Layoutopt tool and has much greater functionality. Some examples of Lint <a
<li>Use compound drawables - A {@link android.widget.LinearLayout} which contains an {@link android.widget.ImageView} and a {@link android.widget.TextView} can be more efficiently handled as a compound drawable.</li>
140
+
<li>Merge root frame - If a {@link android.widget.FrameLayout} is the root of a layout and does not provide background or padding etc, it can be replaced with a merge tag which is slightly more efficient.</li>
141
+
<li>Useless leaf - A layout that has no children or no background can often be removed (since it is invisible) for a flatter and more efficient layout hierarchy.</li>
142
+
<li>Useless parent - A layout with children that has no siblings, is not a {@link android.widget.ScrollView} or a root layout, and does not have a background, can be removed and have its children moved directly into the parent for a flatter and more efficient layout hierarchy.</li>
143
+
<li>Deep layouts - Layouts with too much nesting are bad for performance. Consider using flatter layouts such as {@link android.widget.RelativeLayout} or {@link android.widget.GridLayout} to improve performance. The default maximum depth is 10.</li>
144
+
</ul>
145
+
146
+
<p>Another benefit of Lint is that it is integrated into the Android Development Tools for Eclipse (ADT 16+). Lint automatically runs whenever you export an APK, edit and save an XML file or use the Layout Editor. To manually force Lint to run press the Lint button in the Eclipse toolbar.</p>
<p>When used inside Eclipse, Lint has the ability to automatically fix some issues, provide suggestions for others and jump directly to the offending code for review. If you don’t use Eclipse for your development, Lint can also be run from the command line. More information about Lint is available at <a href="http://tools.android.com/tips/lint">tools.android.com</a>.</p>
151
+
152
+
134
153
135
-
<p>It is always good practice to also run the <a
136
-
href="{@docRoot}guide/developing/tools/layoutopt.html">layoutopt</a> tool on your final layout files
137
-
to search for places in your view hierarchy that may be optimized. Layoutopt is also in your SDK
138
-
{@code tools/} directory and takes a layout directory name or a space-separated list of layout files
139
-
that you'd like to inspect.</p>
140
154
141
-
<p>When you run {@code layoutopt} on a layout file, it prints a line number for each issue found, a
142
-
description of the issue, and for some types of issues it also suggests a resolution. For
143
-
example:</p>
144
155
145
-
<pre class="no-pretty-print classic">
146
-
$ layoutopt samples/
147
-
samples/compound.xml
148
-
7:23 The root-level <FrameLayout/> can be replaced with <merge/>
149
-
11:21 This LinearLayout layout or its FrameLayout parent is useless
150
-
samples/simple.xml
151
-
7:7 The root-level <FrameLayout/> can be replaced with <merge/>
152
-
</pre>
153
156
154
-
<p>After you apply the suggested layout optimizations, run Hierarchy Viewer again to inspect the
0 commit comments