setElevation vs setTranslationZ vs setZ

Lollipop has all these new features for the View class. What exactly are the differences between them and why do we need so many functions for them?

I read the documents and I want to understand (or better understand) the difference and it is necessary for each of them, so that I know when to use each of them:

  • height

base z depth of view

There must be a dimension value that is added with a unit floating point, such as "14.5 cP". The available units are: px (pixels), dp (density independent pixels), sp (scaled pixels based on preferred font size), inches (mm), mm (millimeters).

It can also be a link to a resource (in the form "@ [package:] type: name") or a theme attribute (in the form "? [Package:] [type:] name") containing a value of this type.

This corresponds to the height of the global attribute resource symbol.

So where does it start?

  1. translationZ

translation into z view. This value is added to its height.

There must be a dimension value that is added with a unit floating point, such as "14.5 cP". The available units are: px (pixels), dp (density independent pixels), sp (scaled pixels based on preferred font size), inches (mm), mm (millimeters).

It can also be a link to a resource (in the form "@ [package:] type: name") or a theme attribute (in the form "? [Package:] [type:] name") containing a value of this type.

This corresponds to the resource symbol symbol of the global attribute Z.

So, is this added in addition to "elevation"? Why is this necessary?

  1. And the most confusing: setZ

Sets the visual z position of this view in pixels. This is equivalent to setting the value of the translationZ property as the difference between x and the current height property.

I do not understand the explanation for this at all. Does it affect the shadow? What is it used for? To handle the case that 2 views have the same common elavation value? Does animating this value change the way the view is displayed?

+5
source share

All Articles