源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-10-25 13:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android仿打开微信红包动画效果实现代码
首先看下效果: [img]http://files.jb51.net/file_images/article/201712/2017121110465929.gif[/img] [b]实现原理:[/b] 准备3张不同角度的图片,通过AnimationDrawable帧动画进行播放即可 [b]代码实现:[/b] 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();//启动动画
[b]总结[/b] 以上所述是小编给大家介绍的Android仿打开微信红包动画效果实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部