Difference between elevation and translationZ

JavierSegoviaCordoba picture JavierSegoviaCordoba · Mar 31, 2015 · Viewed 16.7k times · Source

I tried both features and I don't know really why I should use elevation instead of translationz or viceversa.

Both generate shadow when I used them.

I should use at same time (with the same value)? I should use just one?

Thank you in advance!

EDIT:

I did a visual comparison to can see it clearly:

comparison elevation vs translationZ

The conclusion that I get is (at least with this range of 0 to 16 dp) one of them is dispensable.

I see the same shadow in 8 vs 8 and 16 vs 16 and the same shadow in 16 vs 8+8.

But I haven't a great vision, what do you think guys?

Answer

Ferdau picture Ferdau · Mar 31, 2015

That is because the actual Z value is the sum of the elevation and the translationZ

From the docs, the elevation is "base z depth of the view" and this is a static variable, while translationZ is dynamic.

So elevation is your start value and for animations you should use translationZ.

Source