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



首先看下效果:



Android仿打开微信红包动画效果实现_第1张图片


实现原理:

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

代码实现:

1、编写动画xml文件:


<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、设置布局控件

"@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();//启动动画
完工。。


 


你可能感兴趣的:(小Demo)