Skip to content

Commit 942b823

Browse files
geekyouupAndroid (Google) Code Review
authored andcommitted
Merge "docs: Added Lint into Android Training and removed Layoutopt." into ics-mr1
2 parents 01011c3 + 0980e41 commit 942b823

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed
21.6 KB
Loading

docs/html/training/improving-layouts/optimizing-layout.jd

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ next.link=reusing-layouts.html
1818
<ol>
1919
<li><a href="#Inspect">Inspect Your Layout</a></li>
2020
<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>
2222
</ol>
2323

2424
<!-- other docs (NOT javadocs) -->
@@ -44,7 +44,7 @@ is inflated repeatedly, such as when used in a {@link android.widget.ListView} o
4444
android.widget.GridView}.</p>
4545

4646
<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
4848
href="{@docRoot}guide/developing/tools/layoutopt.html">Layoutopt</a> to examine and optimize your
4949
layout.</p>
5050

@@ -53,7 +53,7 @@ layout.</p>
5353
<h2 id="Inspect">Inspect Your Layout</h2>
5454

5555
<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
5757
you to analyze your layout while your application is running. Using this tool helps you discover
5858
bottlenecks in the layout performance.</p>
5959

@@ -130,27 +130,28 @@ example of how each layout has appropriate uses and you should carefully conside
130130
layout weight is necessary.</p>
131131

132132

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
136+
href="http://tools.android.com/tips/lint-checks">rules</a> are:</p>
137+
138+
<ul>
139+
<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>
147+
148+
<img src="{@docRoot}images/training/lint_icon.png" alt="" />
149+
150+
<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+
134153

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>
140154

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>
144155

145-
<pre class="no-pretty-print classic">
146-
$ layoutopt samples/
147-
samples/compound.xml
148-
7:23 The root-level &lt;FrameLayout/&gt; can be replaced with &lt;merge/&gt;
149-
11:21 This LinearLayout layout or its FrameLayout parent is useless
150-
samples/simple.xml
151-
7:7 The root-level &lt;FrameLayout/&gt; can be replaced with &lt;merge/&gt;
152-
</pre>
153156

154-
<p>After you apply the suggested layout optimizations, run Hierarchy Viewer again to inspect the
155-
performance changes.</p>
156157

0 commit comments

Comments
 (0)