Android仿打开微信红包动画效果实现代码

时间:2019-04-11
本文章向大家介绍Android仿打开微信红包动画效果实现代码,主要包括Android仿打开微信红包动画效果实现代码使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

首先看下效果:

实现原理:

准备3张不同角度的图片,通过AnimationDrawable帧动画进行播放即可

代码实现:

1、编写动画xml文件:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> 
 <item android:drawable="@mipmap/open" android:duration="400"></item> 
 <item android:drawable="@mipmap/open3" android:duration="400"></item> 
 <item android:drawable="@mipmap/open2" android:duration="400"></item>
</animation-list>

根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画  根标签下,通过item标签对动画中的每一个图片进行声明 
android:duration 表示展示所用的该图片的时间长度 ,可通过该参数来设置图片旋转的速度

2、设置布局控件

<ImageView 
 android:padding="@dimen/dimen_5" 
 android:id="@+id/iv_open" 
 android:layout_centerInParent="true" 
 android:layout_width="@dimen/dimen_100" 
 android:layout_height="@dimen/dimen_100" 
android:background="@drawable/open_red_animation_drawable" />

注意是使用background来加载动画而不是src

3、代码中启动需要播放动画的控件

//ivOpen指的是需要播放动画的ImageView控件
AnimationDrawable animationDrawable = (AnimationDrawable)ivOpen.getBackground();
animationDrawable.start();//启动动画

总结

以上所述是小编给大家介绍的Android仿打开微信红包动画效果实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!