AnimatedVectorDrawable的一些碎碎念

关于Vector及AnimatedVectorDrawable的一些基本知识,请参见徐医生的Android Vector曲折的兼容之路 ,写的很全,很棒。

读完上文之后,我们对静态的vector和动态的AnimatedVectorDrawable有了一定的了解,并做了一些小的尝试,本文里边主要说的是一些兼容性的问题及解决方案。

从AppCompat23.2开始,Google开始支持在低版本上使用Vector,兼容性还是相当不错的,但是动态的AnimatedVectorDrawable在低版本的兼容上边问题就很大了,除了目前不能在L之下的版本上使用以外,还有一些其他的坑。

    AnimatedVectorDrawableCompat animatedVectorDrawable = (AnimatedVectorDrawableCompat) getResources().getDrawable(R.drawable.vectalign_animated_vector_drawable_start_to_end);
    ImageView imageView = (ImageView) findViewById(R.id.image_svg);
    imageView.setImageDrawable(animatedVectorDrawable);
    animatedVectorDrawable.start();

上述代码可以让我们在Android L以上去播放一个AnimatedVectorDrawable,但在低版本上xml中的标签animated-vector会报错:org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag animated-vector

即使用上了AnimatedVectorDrawableCompat也无效,所以如果不用三方库(后边会说),只能将其分开两种版本来写:API21以上用动画,A

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值