Week 5
Week 5
Lesson 5
Optional material
Android
Improving Layouts
HierarchyViewer & lint
Victor Matos
Cleveland State University
Portions of this page are reproduced from work created and shared by Google and used according to terms
described in the Creative Commons 3.0 Attribution License.
Improving Layouts
Reference: http://developer.android.com/tools/debugging/debugging-ui.html
To help debug issues in your layout and Manifest, the Android SDK provides the Hierarchy
Viewer and lint tools.
• The Hierarchy Viewer application allows you to debug and optimize your user
interface.
• It provides a visual representation of the layout's View hierarchy (the View
Hierarchy window) and
• Android lint is a static code scanning tool that helps you optimize the layouts and
layout hierarchies of your applications, as well as detect other common coding
problems.
2
Lesson 5
Improving Layouts
Hierarchy Viewer
Shows the tree structure of your XML layout. Assume the CoffeeOrder app is
running
i iin the
h emulator.
l To execute the
h program d do the
h ffollowing:
ll i
Improving Layouts
Hierarchy Viewer
The next screen offers a list of activities.
Choose
h the
h activity
i i whose
h UI iis to b
be explored
l d
4
Lesson 5
Improving Layouts
Hierarchy Viewer
For details on how to use the tool see video:
http://www.youtube.com/watch?v=PAgE7saQUUY&feature=player_embedded
Improving Layouts
Hierarchy Viewer – Detail
Rendering time includes:
1 Measuring,
1. Meas rin
2. Laying out,
3. Drawing
6
Lesson 5
Improving Layouts
Hierarchy Viewer – Detail
The lower right panel displays an outline
of the UI
UI.
Improving Layouts
Pixel Perfect
• Gives a very detailed depiction of the UI.
• Useful way of saving templates, and
adding Overlay Layers to ‘beautify’
beautify the
screen design.
For details see the video:
http://www.youtube.com/watch?v=C45bMZGdN7Y&feature=player_embeddedves
8
Lesson 5
Lint
Improving Layouts
Use lint on your resource directories to check for inefficiencies or other types of
problems that could be affecting the performance of your application.
c:\Users\1002125\workspace-ANDROID> lint 04-6-UI-Coffee-Order
^
res\layout\main.xml:92: Warning: Avoid using "px" as units; use "dp" instead [PxUsage]
res\values\strings.xml:3: Warning: The resource R.string.hello appears to be unused [UnusedResources]
<string name=
name="hello">Hello
hello >Hello World
World, Main!</string>
^
res: Warning: Missing density variation folders in res: drawable-xhdpi [IconMissingDensityFolder]
res\layout\main.xml:24: Warning: [I18N] Hardcoded string "What type of coffee?", should use @string resource [HardcodedText]
^
res\layout\main.xml:36: Warning: [I18N] Hardcoded string "Decaf", should use @string resource [HardcodedText]
<RadioButton
^
…
1 errors, 13 warnings
Improving Layouts
Questions?
10