@rrafols
http://blog.rafols.org
What your mother didn't tell you
about Custom Views
@rrafols
http://blog.rafols.org
Who I am?
@rrafols
http://blog.rafols.org
Raimon Ràfols
@rrafols
+RaimonRafolsMontane
http://blog.rafols.org
@rrafols
http://blog.rafols.org
Software Engineering Manager
Imagination Technologies
@ImaginationPR
imgtec.com
@rrafols
http://blog.rafols.org
Custom Views
Motivation
@rrafols
http://blog.rafols.org
Why?
@rrafols
http://blog.rafols.org
Advantages?
@rrafols
http://blog.rafols.org
Benefits?
@rrafols
http://blog.rafols.org
Should we use them on all kind
of projects?
@rrafols
http://blog.rafols.org
Or should we prioritise the use of
standard components only?
@rrafols
http://blog.rafols.org
Isn't it too much effort?
@rrafols
http://blog.rafols.org
Design
Programming
Testing
@rrafols
http://blog.rafols.org
Let's build one Custom View!
@rrafols
http://blog.rafols.org
@rrafols
http://blog.rafols.org
Is that all?
@rrafols
http://blog.rafols.org
@rrafols
http://blog.rafols.org
What's the result?
@rrafols
http://blog.rafols.org
@rrafols
http://blog.rafols.org
@rrafols
http://blog.rafols.org
Layout parameters
@rrafols
http://blog.rafols.org
MATCH_PARENT
WRAP_CONTENT
SPECIFIC SIZE
@rrafols
http://blog.rafols.org
MeasureSpec.AT_MOST
MeasureSpec.EXACTLY
MeasureSpec.UNSPECIFIED
@rrafols
http://blog.rafols.org
What's the mapping
between these values?
@rrafols
http://blog.rafols.org
WIDTH: EXACTLY
HEIGHT: EXACTLY
@rrafols
http://blog.rafols.org
WIDTH: EXACTLY
HEIGHT: AT_MOST
@rrafols
http://blog.rafols.org
WIDTH: EXACTLY
HEIGHT: UNSPECIFIED
@rrafols
http://blog.rafols.org
Parametrise
@rrafols
http://blog.rafols.org
Define parameters in
a xml resource file
attrs.xml
@rrafols
http://blog.rafols.org
Be nice - Always recycle!
@rrafols
http://blog.rafols.org
Tips
@rrafols
http://blog.rafols.org
Don't create Paint objects on
onDraw. As a rule of thumb don't
allocate memory on draw
methods.
@rrafols
http://blog.rafols.org
API support & limitations
@rrafols
http://blog.rafols.org
@rrafols
http://blog.rafols.org
@rrafols
http://blog.rafols.org
What could be done?
@rrafols
http://blog.rafols.org
Detect version on runtime and
adapt dynamically
@rrafols
http://blog.rafols.org
?
@rrafols
http://blog.rafols.org
http://developer.android.com/guide/topics/graphics/hardware-accel.html

Android Custom Views