TranslationZ实际上在Android中做什么? [英] What does TranslationZ actually do in Android?

查看:840
本文介绍了TranslationZ实际上在Android中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在开发android应用程序,在其中尝试实现新的材质设计功能.我尝试同时应用了海拔属性和TranslationZ属性,但无法正常工作.

Hi I am developing android application in which I am trying to implement new material design features. I tried to apply both elevation property and TranslationZ property but it is not working.

<Button
    android:id="@+id/button1"
    style="@style/ButtonStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:text="Name" />  

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="#0073ff" />
    <corners android:radius="16dp" />
</shape>

<style name="ButtonStyle">
        <item name="android:elevation">8dp</item>
        <item name="android:translationZ">8dp</item>
        <item name="android:background">@drawable/file</item>
</style>

推荐答案

TranslationZ是用于动画的动态属性.基本上需要很好地处理高程变化.当您按下按钮时,其高程保持不变,并且其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. This way the View always knows what was the original elevation value and can respond correctly to multiple touch events.

内部Z =高度+平移Z

Internally Z = elevation + translationZ

这篇关于TranslationZ实际上在Android中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆