Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Philly ETE 2017: Loving Lean Android Layouts
Search
Huyen Tue Dao
April 18, 2017
Technology
0
250
Philly ETE 2017: Loving Lean Android Layouts
Huyen's talk at Philly ETE on performance and efficiency in Android layouts.
Huyen Tue Dao
April 18, 2017
Tweet
Share
More Decks by Huyen Tue Dao
See All by Huyen Tue Dao
Less Imperative with More Kotlin
queencodemonkey
0
260
Øredev 2017: Cool ConstraintLayout
queencodemonkey
3
280
Øredev 2017: Measure. Layout. Draw. Repeat.
queencodemonkey
0
350
Be Like Water: Keeping Up with Android
queencodemonkey
2
280
DevFest DC 2017: Cool ConstraintLayout
queencodemonkey
1
13k
Chicago Roboto 2017: Cool ConstraintLayout
queencodemonkey
9
1k
Droidcon Boston 2017: Cool ConstraintLayout
queencodemonkey
6
470
My Life in Android
queencodemonkey
1
340
DevFest MN 2017: Cool ConstraintLayout
queencodemonkey
1
470
Other Decks in Technology
See All in Technology
いまならこう作りたい AWSコンテナ[本格]入門ハンズオン 〜2024年版 ハンズオンの構想〜
horsewin
9
2.1k
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
530
omakaseしないための.rubocop.yml のつくりかた / How to Build Your .rubocop.yml to Avoid Omakase #kaigionrails
linkers_tech
3
740
コンテンツを支える 若手ゲームクリエイターの アートディレクションの事例紹介 / cagamefi-game
cyberagentdevelopers
PRO
1
130
Aurora_BlueGreenDeploymentsやってみた
tsukasa_ishimaru
1
120
AWS re:Inventを徹底的に楽しむためのTips / Tips for thoroughly enjoying AWS re:Invent
yuj1osm
1
570
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
180
IaC運用を楽にするためにCDK Pipelinesを導入したけど、思い通りにいかなかった話
smt7174
1
110
使えそうで使われないCloudHSM
maikamibayashi
0
170
WINTICKETアプリで実現した高可用性と高速リリースを支えるエコシステム / winticket-eco-system
cyberagentdevelopers
PRO
1
190
よくわからんサービスについての問い合わせが来たときの強い味方 Amazon Q について
kazzpapa3
0
220
独自ツール開発でスタジオ撮影をDX!「VLS(Virtual LED Studio)」 / dx-studio-vls
cyberagentdevelopers
PRO
1
180
Featured
See All Featured
It's Worth the Effort
3n
183
27k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
Statistics for Hackers
jakevdp
796
220k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
14
1.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Thoughts on Productivity
jonyablonski
67
4.3k
What's new in Ruby 2.0
geeforr
342
31k
Transcript
HUYEN TUE DAO @QUEENCODEMONKEY LOVING LEAN ANDROID LAYOUTS
LOVING LEAN ANDROID LAYOUTS <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/help_im_being_repressed" android:textStyle="bold" style="@style/TextAppearance.AppCompat.Body1" /> <ImageView android:layout_width="0dp" android:layout_height=“@dimen/image_height" android:layout_weight="2" android:src="@drawable/berries_plate" android:scaleType="centerCrop" android:contentDescription="@null" /> <ImageView android:layout_width="0dp" android:layout_height="@dimen/image_height" android:layout_weight="1" android:src="@drawable/creme_brulee" android:scaleType="centerCrop" android:contentDescription="@null" /> </LinearLayout>
LOVING LEAN ANDROID LAYOUTS WHY LEAN LAYOUTS FINDING PROBLEMS FIXING
PROBLEMS GOOD PRACTICES
HOW ANDROID DRAWS LAYOUTS MEASURE LAYOUT DRAW DEPTH-FIRST TRAVERSAL INFLATION
PARENT MEASURES EACH CHILD CHILD CALCULATES MEASURED WIDTH/HEIGHT MEASURE OWN
CHILDREN (IF ANY) HOW ANDROID DRAWS LAYOUTS MEASURE LAYOUT DRAW
HOW ANDROID DRAWS LAYOUTS MEASURE LAYOUT DRAW PARENT SIZES AND
POSITIONS CHILD
HOW ANDROID DRAWS LAYOUTS MEASURE LAYOUT DRAW PARENT DRAWS PARENT
TELLS CHILDREN TO DRAW
LOVING LEAN ANDROID LAYOUTS WHY LEAN LAYOUTS FINDING PROBLEMS FIXING
PROBLEMS GOOD PRACTICES
WHY LEAN LAYOUTS #PERFMATTERS
PERFORMANCE = RESOURCES USED ∝COMPLEXITY
PERFORMANCE = RESOURCES USED ∝COMPLEXITY = # VIEWS/DEPTH OF HIERARCHY
PERFORMANCE = RESOURCES USED ∝COMPLEXITY = # VIEWS/DEPTH OF HIERARCHY
= # EXECUTIONS OF onMeasure()/onLayout()
PERFORMANCE = RESOURCES USED ∝COMPLEXITY = # VIEWS/DEPTH OF HIERARCHY
= # EXECUTIONS OF onMeasure()/onLayout() BAD PERFORMANCE = UI JANK
MAINTAINABILITY WHY LEAN LAYOUTS
RESOURCES USED∝COMPLEXITY ∝EFFORT TO MAINTAIN AND REFACTOR = READABILITY (PARSING
+ NESTING) + STABILITY
CHANGE IN SIZE/POSITION STARTS MEASURE/LAYOUT STARTING AT ROOT. SOME LAYOUTS
NEED MULTIPLE MEASURE/LAYOUT PASSES, E.G. RELATIVELAYOUT LISTS MAKE MANY COPIES OF SAME LAYOUT DEEP HIERARCHIES INCREASE COMPLEXITY AND DEPENDENCY WHERE IS THE PROBLEM?
LOVING LEAN ANDROID LAYOUTS WHY LEAN LAYOUTS FINDING PROBLEMS FIXING
PROBLEMS GOOD PRACTICES
HIERARCHY VIEWER FINDING PROBLEMS VISUALIZATION ANDROID DEVICE MONITOR BEST ON
PHYSICAL DEVICE | 4.1+
None
None
LAYOUT INSPECTOR FINDING PROBLEMS ANDROID MONITOR EXAMINE/DEBUG LAYOUT EVENTUALLY SUPERSEDE
HIERARCHY VIEWER
None
BLUEPRINT VIEW FINDING PROBLEMS
SYSTRACE FINDING PROBLEMS SYSTEM + APPLICATION PROCESS EXECUTION DATA DATA
TRACE → INTERACTIVE REPORTS SMOOTH UI → 60FPS → 16.6MS/FRAME
None
None
DUMPSYS FINDING PROBLEMS SYSTEM SERVICES STATUS FRAMES OF ANIMATION adb
shell dumpsys gfxinfo <PACKAGE_NAME> DETAILED FRAME TIMING INFO adb shell dumpsys gfxinfo <PACKAGE_NAME> framestats
OnFrameMetricsAvailableListener FINDING PROBLEMS MARSHMALLOW PUB/SUB API EQUIVALENT TO DUMPSYS FRAMESTATS
EXCEPT NOT LIMITED TO 120 FRAMES
LOVING LEAN ANDROID LAYOUTS WHY LEAN LAYOUTS FINDING PROBLEMS FIXING
PROBLEMS GOOD PRACTICES
MAKE LINT HAPPY FIXING PROBLEMS
None
LINT USELESS PARENT
LINT NESTED WEIGHTS
LINT TOO MUCH NESTING
SIMPLIFY AND REDUCE FIXING PROBLEMS
None
<LinearLayout > <ImageView /> <TextView /> </LinearLayout>
3 VIEWS, 2 LEVELS
<TextView… android:drawablePadding=“…" android:drawableEnd=“…"/> 1 VIEW, 1 LEVEL
None
None
SPANNABLES
<LinearLayout…> <TextView… style="@style/StyleA" /> <TextView… style="@style/StyleB" />
<TextView… style="@style/StyleA" /> </LinearLayout> 4 VIEWS, 2 LEVELS
<TextView…/> + Spannables 1 VIEW, 1 LEVEL
None
None
<FrameLayout… android:padding=“…” android:background=“…“> <LinearLayout /> </FrameLayout> 2 VIEWS,
2 LEVELS
<LinearLayout… android:padding=“…” android:background=“…“/> 1 VIEW, 1 LEVEL
None
None
<LinearLayout > <LinearLayout> <TextView /> <TextView />
</LinearLayout> <TextView /> </LinearLayout> 5 VIEWS, 3 LEVELS
<ConstraintLayout…> <TextView… /> <TextView… /> <TextView… />
</ConstraintLayout> 4 VIEWS, 2 LEVEL
CONSTRAINTLAYOUT MORE EXPRESSIVE MORE PERFORMANT FLATTEN HIERARCHIES REDUCE VIEWS
None
GO CUSTOM FIXING PROBLEMS CUSTOM VIEW/VIEWGROUP TOTAL CONTROL OVER LAYOUT/DRAW
BALANCE PERFORMANCE GAINS AND DEVELOPMENT EFFORT
GO CUSTOM FIXING PROBLEMS CUSTOM VIEW/VIEWGROUP TOTAL CONTROL OVER LAYOUT/DRAW
BALANCE PERFORMANCE GAINS AND DEVELOPMENT EFFORT
LOVING LEAN ANDROID LAYOUTS WHY LEAN LAYOUTS FINDING PROBLEMS FIXING
PROBLEMS GOOD PRACTICES
ANTICIPATE AND DEVELOP GOOD HABITS GOOD PRACTICES
SIMPLEST SOLUTIONS WHERE POSSIBLE GOOD PRACTICES
FEWER AND FLATTER NO RELATIVELAYOUT AT ROOT GOOD PRACTICES
DON’T LET PROBLEMS ACCUMULATE GOOD PRACTICES
BALANCE PERFORMANCE GAINS WITH DEVELOPMENT EFFORT GOOD PRACTICES
THANK YOU! SPEAKERDECK.COM/QUEENCODEMONKEY YOUTUBE.COM/ANDROIDDIALOGS RANDOMLYTYPING.COM HUYEN TUE DAO @QUEENCODEMONKEY
REFERENCES 63 ANDROID PERFORMANCE PATTERNS, WHY 60FPS? https://youtu.be/CaMTIgxCSqU DEVELOPING FOR
ANDROID: THE NAUGHTY BITS https://youtu.be/Q2qQoJlwqlk?t=36m4s HIERARCHY VIEWER https://developer.android.com/studio/profile/hierarchy-viewer.html LAYOUT INSPECTOR http://tools.android.com/tech-docs/layout-inspector
REFERENCES 64 TESTING DISPLAY PERFORMANCE http://developer.android.com/training/testing/performance.html ANALYZING UI PERFORMANCE WITH
SYSTRACE http://developer.android.com/tools/debugging/systrace.html OPTIMIZING LAYOUT HIERARCHIES http://developer.android.com/training/improving-layouts/optimizing-layout.html ANDROID PERFORMANCE PATTERNS, DOUBLE LAYOUT TAXATION https://www.youtube.com/watch?v=dB3_vgS-Uqo ANDROID PERFORMANCE PATTERN, INVALIDATIONS, LAYOUTS, AND PERFORMANCE https://youtu.be/we6poP0kw6E
REFERENCES 65 BUILD A RESPONSIVE UI WITH CONSTRAINTLAYOUT developer.android.com/training/constraint-layout/index.html ANDROID
DEVELOPERS BACKSTAGE: EPISODE 50: CONSTRAINT LAYOUT androidbackstage.blogspot.com/2016/06/episode-50-constraint-layout.html CUSTOM VIEWGROUPS https://sriramramani.wordpress.com/2015/05/06/custom-viewgroups/ MEASURE, LAYOUT, DRAW, REPEAT: CUSTOM VIEWS AND VIEWGROUPS https://youtu.be/dLl0ovmta6A