Android仿打开微信红包实现

首先看下效果:

hongbao.gif

实现原理:

准备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();//启动动画

完工。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容