Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between elevation and translationZ

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?

like image 474
JavierSegoviaCordoba Avatar asked Mar 31 '15 11:03

JavierSegoviaCordoba


People also ask

What is TranslationZ?

TranslationZ is a dynamic property used for animation. Basically it's needed to nicely handle elevation changes. When you press a button, its elevation remains unchanged and its translationZ is being animated.

What is elevation in Android?

Elevation helps users understand the relative importance of each element and focus their attention to the task at hand. The elevation of a view, represented by the Z property, determines the visual appearance of its shadow: views with higher Z values cast larger, softer shadows.


1 Answers

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

like image 56
Ferdau Avatar answered Sep 22 '22 17:09

Ferdau