Elevation animation on click on CardView

帅比萌擦擦* 提交于 2019-12-03 06:34:30

I've tried your code, maybe you have simply add the state to second selector element.

So change this line

<item>

with this

<item android:state_enabled="true" android:state_pressed="false">

The complete code will be

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true" android:state_pressed="true">
        <objectAnimator android:duration="@android:integer/config_shortAnimTime"
            android:propertyName="translationZ" android:valueTo="@dimen/touch_raise"
            android:valueType="floatType" />
    </item>
    <item android:state_enabled="true" android:state_pressed="false">
        <objectAnimator android:duration="@android:integer/config_shortAnimTime"
            android:propertyName="translationZ" android:valueTo="0dp"
            android:valueType="floatType" />
    </item>
</selector>

You tried to create this .xml in res/anim folder.

You should create on res/animator, if don't exist is easy to create.

But if you search for the problem it already give you a possible solution

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