-
Notifications
You must be signed in to change notification settings - Fork 377
Elevation
ZieIony edited this page May 7, 2015
·
2 revisions
It's a concept of a distance between a view and its parent. It works like this:
- Each view with non-zero elevation value casts a shadow.
- Each view with elevation set to E covers views with elevation set to less than E.
- Elevation is a static component of z position. The dynamic part is called translationZ and is used for animation. Keeping these two as separate values allows proper handling of multiple taps and animations.
- Internally z = elevation + translationZ
- Elevation system works only inside one layout. Children attached to two different layouts won't affect each other.
The most important thing to remember is that the elevation changes the children drawing order. It may be confusing as many developers were used to the order of xml declarations.
Elevation can be easily implemented using one method available in Android since API 1. See:
http://developer.android.com/reference/android/view/ViewGroup.html#getChildDrawingOrder(int, int)
To implement an elevation system you have to:
- Provide a way of determining an elevation of a view. The easiest way is to add a
float elevation
field. - Create a comparator class used for sorting items.
- Override the
getChildDrawingOrder
method.
Copyright 2015 Marcin Korniluk 'Zielony'