android Material Desgin动效——SVG动画

参考博客:蓝色的天空ywj 简书

一个成功的AnimatedVectorDrawable由三部分组成:animator/anim_rotat;drawable/anim_vector;drawable/vector

drawable/vector:定义动画初始的样子,可缺省
animator/anim_rotat:定义动画(可有多个)
drawable/anim_vector:管理animator/anim_rotat和drawable/vector

对于AnimatedVectorDrawable的定义上面两个博客都说得很详细了,我想说的是动画的启动方法:
为了让动画可更换推荐下面的写法:

ImageView imageView =  (ImageView)  findViewById(R.id.ImageView1);
//此处演示更换
if(current%2 ==0){
    imageView.setImageResource(R.drawable.anim_vector);  // 设置Resource为动画资源
}else{
    imageView.setImageResource(R.drawable.anim_vector2);  // 设置Resource为动画资源
}
try{ //推荐try-catch
    Animatable animatable = (Animatable) imageView.getDrawable();//推荐抽成全局变量可以销毁节约内存
    animatable.start();
}catch (Exception e){
    e.printStackTrace();
}
发布了66 篇原创文章 · 获赞 5 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/yuemitengfeng/article/details/86527096