Android Talks #05 - UI optimization of Android applications

Post on 20-Aug-2015

467 views 1 download

Tags:

transcript

UI optimization of android applications

Dino Kovač

Rules of optimization

1.Don’t.!

2.Don’t… yet.!

3.Profile before optimizing!

–Donald Knuth

“Premature optimization is the root of all evil.”

Tools• Hierarchy Viewer!

• “Show GPU Overdraw” (Developer options, android 4.2+)

Example app• One relevant activity!

• Two lists!

• A compound view as the right list item

View tree

How android draws views1. measure pass - each view stores it’s

measurements!

2. layout pass - each view positions it’s children!

3. draw pass - each view draws itself

Focus of optimization• Flattening layout hierarchy!

• Minimizing overdraw

Layout simplification

<merge />

<merge />

Overdraw

• Pixels get drawn more than once!

• blue(2), green(3), light red(4), dark red(5)!

• mostly multiple backgrounds

Tweaking the selector

Overdraw before/after

Some numbers

Hierarchy depth

Total views Measure Layout Draw Total

Before 9 76 0.354 1.7792 3.3624 5.4956

After 8 52 0.3402 1.0984 2.7098 4.1484

References• http://c2.com/cgi/wiki?RulesOfOptimization!

• http://www.youtube.com/watch?v=URyoiAt8098!

• http://www.youtube.com/watch?v=-FUw8HMbmBQ!

• http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html!

• http://developer.android.com/training/improving-layouts/optimizing-layout.html!

• https://github.com/reisub/android_uioptimizationexample