Android 实战开发 帧动画
来源:互联网 发布:阿里云mysql远程连接 编辑:程序博客网 时间:2024/06/16 13:32
Android 动画分类
1.帧动画
2.补间动画
3.属性动画
一.帧动画
帧动画由动画图形AnimationDrawable生成。 主要常用常有方法
addFrame:添加一幅图片帧,并指定该帧的持续时间(单位毫秒)
setOneShot:设置是否只播放一次。为true 表示只播放一次。为false表示循环播放。
start:开始播放。注意,设置宿主视图后才能进行播放
stop:停止播放
isRunning:判断是否正在播放
有了动画图形,还得又一个宿主视图显示该图形,一般使用图像视图ImageView承载AnimationDrawable。即调用ImageView对象的setImageDrawable方法将动画图形加载到图像视图中。
实现:
1.添加 图片
创建及配置frame_anim.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="@drawable/hb_1" android:duration="50"/> <item android:drawable="@drawable/hb_2" android:duration="50"/> <item android:drawable="@drawable/hb_3" android:duration="50"/> <item android:drawable="@drawable/hb_4" android:duration="50"/></animation-list>2.在MainActivity.java中调用动画protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView frameAnim = findViewById(R.id.frameAnim); frameAnim.setImageResource(R.drawable.frame_anim); AnimationDrawable ad_frame = (AnimationDrawable)frameAnim.getDrawable(); ad_frame.start();}
实现效果
动画已经跑起来了!
显示GIF动画
1.添加loading.gif
2.编写代码
private void showGifAnimation(){ ImageView iv_gif = findViewById(R.id.frameAnim); InputStream is = getResources().openRawResource(R.raw.loading); GifImage gifImage = new GifImage(); int code = gifImage.read(is); if (code == GifImage.STATUS_OK) { GifImage.GifFrame[] frameList = gifImage.getFrames(); AnimationDrawable ad_gif = new AnimationDrawable(); for (int i=0; i<frameList.length; i++) { //BitmapDrawable用于把Bitmap格式转换为Drawable格式 BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), frameList[i].image); ad_gif.addFrame(bitmapDrawable, frameList[i].delay); } ad_gif.setOneShot(false); iv_gif.setImageDrawable(ad_gif); ad_gif.start(); } else if (code == GifImage.STATUS_FORMAT_ERROR) { Toast.makeText(this, "该图片不是gif格式", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "gif图片读取失败:" + code, Toast.LENGTH_LONG).show(); }运行效果
阅读全文
0 0
- Android 实战开发 帧动画
- APP开发实战85-帧动画
- Android 动画实战
- Android属性动画实战
- Android开发之Frame动画(帧动画)
- Android开发 之 帧动画
- Android动画实战-仿简聊App动画菜单
- Android动画机制(1):帧动画、补间动画详解及实战演练
- Android 动画机制及实战
- Android Animator动画小实战
- Android弹簧动画 Rebound实战
- 【Android实战】使用帧动画实现自定义loading加载布局
- android开发:动画-属性动画
- [Android开发实战]金山清理大师(猎豹清理大师)一键加速快捷方式动画实现
- android项目【新闻】项目实战(一):开发启动图并实现动画效果
- APP开发实战86-View动画
- APP开发实战87-属性动画
- APP开发实战88-Activity切换动画
- Android Configuration
- 【实战】android中几个常用的对话框
- 顺序队列
- Event事件
- caffe 与cudnn版本不匹配 ./include/caffe/util/cudnn.hpp:127:41: error: too few arguments to function
- Android 实战开发 帧动画
- 快捷键
- Let’s Encrypt 免费SSL证书自动续期的方法
- ci框架 加载驱动&ci框架使用redis
- AttributeError: module 'requests' has no attribute 'get'”,python中”requests模块“get”属性缺失“的错误该如何解决?
- 递归基本原理及概念--上
- WIN2008+IIS7 ACCESS数据连接失败的解决方法
- spark com.google.common.base.Stopwatch错误解决办法
- Android获取屏幕宽高的四种方法