0% found this document useful (0 votes)
12 views5 pages

Week 5

Uploaded by

justmquan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Week 5

Uploaded by

justmquan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lesson 5

Lesson 5
Optional material

Android
Improving Layouts
HierarchyViewer & lint
Victor Matos
Cleveland State University

Notes are based on:


Android Developers
http://developer.android.com

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

• a magnified view of the display (the Pixel Perfect window).

• 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

• Make sure the emulator is displaying the UI


you want to assess
• Run a DOS shell
• Make sure the path includes access to the
/android-sdk/tools folder. In the DOS shell type
PATH=your-path\Android\android-sdk\tools;%PATH%
PATH your path\Android\android sdk\tools;%PATH%
• Type the command
hierarchyviewer name-offolder-holding-your-app

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

In this case we pick: Main


Click on Load View Hierarchy

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

In the example, the RadioGroup component


consumes a moderate measuring time (yellow
circle) and relatively fast layout & draw timing
(green circles)

Time is miliseconds is also displayed

6
Lesson 5

Improving Layouts
Hierarchy Viewer – Detail
The lower right panel displays an outline
of the UI
UI.

Observe than some stretching might be


needed to make all radio & check boxes
have similar width

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

Scanning 04-6-UI-Coffee-Order: ......................................................................


Scanning 04-6-UI-Coffee-Order (Phase 2): ..
proguard.cfg:19: Error: Obsolete ProGuard file; use -keepclasseswithmembers instead of -keepclasseswithmembernames [Proguard]
-keepclasseswithmembernames class * {
^
AndroidManifest.xml:22: Warning: <uses-sdk> tag appears after <application> tag [ManifestOrder]
<uses-sdk
^
res\layout\main.xml:8: Warning: Unexpected text found in layout file: "á" [ExtraText]

^
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

You might also like