Expected resource of type animator [ResourceType]

错误提示

Error: Expected resource of type animator [ResourceType]

这个错误在编译运行时候并不会出现,但是当需要签名打包的时候,就会报这个异常。

这个错误出现的位置位于自定义View中使用动画的这一行,代码如下:

AnimatorInflater.loadAnimator(context, R.anim.scale_with_alpha)

其中 /res/anim/scale_with_alpha.xml 资源文件的代码如下:

?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:ordering="together">
    <objectAnimator
        android:propertyName="scaleX"
        android:duration="@android:integer/config_shortAnimTime"
        android:valueType="floatType"
        android:valueFrom="1.0"
        android:valueTo="1.8"/>

    <objectAnimator
        android:propertyName="scaleY"
        android:duration="@android:integer/config_shortAnimTime"
        android:valueType="floatType"
        android:valueFrom="1.0"
        android:valueTo="1.8"/>


    <objectAnimator
        android:propertyName="alpha"
        android:duration="@android:integer/config_shortAnimTime"
        android:valueType="floatType"
        android:valueFrom="0.5"
        android:valueTo="1.0"/>
</set>

错误原因

将动画(Animator)资源放在了错误的文件夹下,在早期的android版本中 AnimatorInflater可以加载任何文件夹下的动画文件,但在新的android版本对动画资源的管理有了更严格的标准。

  • /res/anim/ 文件夹下面存放 R.anim.* 类型的 视图动画(View Animations)
  • /res/animator/ 文件夹下面存放R.animator.* 类型的 属性动画(Animators)

这种错误是属于警告,所以才会在调试的时候正常编译,但却在编译签名包的时候失败。

解决方式

第一种

将属性动画(Animators)资源 从/res/anim/ 移至/res/animator/目录。

第二种

在使用 AnimatorInflater 的方法处,加上 @SuppressWarnings("ResourceType"),过滤该警告,则可以正常通过签名编译。

例如:

@SuppressWarnings("ResourceType")
public void initAnim() {
    AnimatorInflater.loadAnimator(context, R.anim.scale_with_alpha);
}

参考链接

http://stackoverflow.com/questions/34293718/expected-resource-of-type-animator-resourcetype

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值