What does TranslationZ actually do in Android?

和自甴很熟 提交于 2019-12-05 02:29:16

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. This way the View always knows what was the original elevation value and can respond correctly to multiple touch events.

Internally Z = elevation + translationZ

Simple Fix

Your problem with losing the touch feedback & Z animations when updating the style comes from not extending the parent android:Widget.Material.Button in your style. If you do that, you won't have to do any manual animation or touch feedback. Just overwrite what you need!

Z-depth explanation

As per the documentation, TranslationZ is just the dynamic component of the Z value. What this means is that when you animate your views in the Z-axis (with ViewPropertyAnimator and such), the animation state will start from the static component of the Z value, the elevation, and will end at the full Z value with with the translation component being the change in between, or the delta.

Z = elevation + translationZ

To implement an animation with translationZ, you'd need to make a StateListAnimator. In your particular case, because you are not animating anything, in order to set a Z-depth to your Button, you just need elevation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!