本文介绍了单击CardView时的高程动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将海拔动画添加到我的 android.support.v7.widget.CardView
中,就像材质样式 Button
s。我试图设置 StateListAnimator
:
I want to add the elevation animation to my android.support.v7.widget.CardView
, just like the material style Button
s do. I've tried to set a StateListAnimator
:
android:stateListAnimator="@anim/selector_raise"
在 res / anim中指向我的选择器
:
<?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>
<objectAnimator android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ" android:valueTo="0dp"
android:valueType="floatType" />
</item>
</selector>
,但是Android Studio给了我错误:
but Android Studio gives me the error:
必须声明元素选择器
这样做的正确方法是什么?
What's the right way to do that?
推荐答案
您试图在 res / anim
文件夹中创建此.xml。
You tried to create this .xml in res/anim
folder.
如果不存在,则应该在 res / animator
上创建。
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
这篇关于单击CardView时的高程动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!