33

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?

rnrneverdies
  • 13,347
  • 9
  • 57
  • 89
JavierSegoviaCordoba
  • 5,841
  • 7
  • 32
  • 48

1 Answers1

34

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

CopsOnRoad
  • 109,635
  • 30
  • 367
  • 257
Ferdau
  • 1,505
  • 1
  • 11
  • 20
  • About your answer, I can get the same solution using always translationZ, at start and later doing animation (example, start at 8dp and translate it to 16dp, and later come back to 8dp), that using elevation + translation – JavierSegoviaCordoba Apr 01 '15 at 17:41
  • @Dahnark That is true, but for example when you have multiple items with a pop-out (or zoom or....) animation, you can still use the elevation property to display the elevation of all those elements separately. – Ferdau Apr 02 '15 at 08:56