详解android 中animation-list 动画的应用
作者:追梦小乐 时间:2022-09-13 18:28:31
来自同事_Smile的封装应用,记录学习一下,分享给大家,具体如下:
1、AnimImageViewLoader类的封装
/**
* 适用于animation-list 动画
* Created by _Smile on 2016/6/13.
*/
public class AnimImageViewLoader extends ImageView {
private AnimationDrawable frameAnimation;
public AnimImageViewLoader(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public AnimImageViewLoader(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public AnimImageViewLoader(Context context) {
super(context);
init();
}
/**
* 初始化动画信息
*/
private void init() {
frameAnimation = (AnimationDrawable) getBackground();
post(new Runnable(){
public void run(){
frameAnimation.start();
}
});
}
/**
* 开启动画显示
*/
public void startAnimation() {
frameAnimation = (AnimationDrawable) getBackground();
post(new Runnable() {
@Override
public void run() {
frameAnimation.start();
}
});
}
/**
* 关闭动画显示
*/
public void stopAnimation() {
post(new Runnable() {
@Override
public void run() {
frameAnimation.stop();
}
});
}
}
2、布局文件
<com.tecsun.tsb.res.widget.AnimImageViewLoader
android:id="@+id/aiv_take_id_card_pic"
style="@style/style_wrap_content"
android:layout_alignTop="@id/iv_id_card_take_pic_main"
android:background="@drawable/anim_id_card_positive_pic" />
3、在代码中的调用
AnimImageViewLoader aivIdCardPic = xFindViewById(R.id.aiv_take_id_card_pic);
aivIdCardPic.setBackgroundResource(R.drawable.anim_id_card_negative_pic);
aivIdCardPic.startAnimation();
4、R.drawable.anim_id_card_negative_pic文件内容
<?xml version="1.0" encoding="utf-8"?>
<!--图片动画-->
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/ic_id_card_negative_01" android:duration="300"/>
<item android:drawable="@mipmap/ic_id_card_negative_02" android:duration="300"/>
<item android:drawable="@mipmap/ic_id_card_negative_03" android:duration="300"/>
<item android:drawable="@mipmap/ic_id_card_negative_04" android:duration="300"/>
<item android:drawable="@mipmap/ic_id_card_negative_05" android:duration="300"/>
<item android:drawable="@mipmap/ic_id_card_negative_06" android:duration="300"/>
</animation-list>
来源:https://www.jianshu.com/p/23f3d3b3ca66
标签:android,animation-list
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android Alertdialog(实现警告对话框)
2022-03-02 10:57:54
![](https://img.aspxhome.com/file/2023/7/138367_0s.gif)
Java如何使用ReentrantLock实现长轮询
2023-11-26 00:09:08
java中Path和ClassPath用法比较
2022-03-15 03:41:26
java8学习教程之函数引用的使用方法
2023-08-28 12:03:19
idea2020.1无法自动加载maven依赖的jar包问题及解决方法
2021-06-13 17:40:36
![](https://img.aspxhome.com/file/2023/6/88506_0s.jpg)
深入了解Java中finalize方法的作用和底层原理
2023-06-18 00:31:35
![](https://img.aspxhome.com/file/2023/6/78986_0s.png)
Android软键盘挡住输入框的终极解决方案
2022-04-30 01:16:47
![](https://img.aspxhome.com/file/2023/4/117164_0s.png)
解决Jenkins集成SonarQube遇到的报错问题
2023-11-24 08:54:10
![](https://img.aspxhome.com/file/2023/6/64396_0s.png)
Java中super关键字介绍以及super()的使用
2021-09-20 06:31:11
java中重载、覆盖和隐藏三者的区别分析
2021-09-30 22:16:48
深入学习Java 热部署的知识
2023-10-16 18:23:24
![](https://img.aspxhome.com/file/2023/3/71673_0s.png)
Android ViewModel创建不受横竖屏切换影响原理详解
2023-08-31 21:21:20
![](https://img.aspxhome.com/file/2023/7/137467_0s.png)
C++中const的实现细节介绍(C,C#同理)
2022-10-21 19:43:12
Java之 TreeSet的详细使用说明
2021-08-22 14:52:22
![](https://img.aspxhome.com/file/2023/8/77078_0s.jpg)
Android编程设计模式之迭代器模式详解
2023-06-07 01:25:42
![](https://img.aspxhome.com/file/2023/2/128952_0s.png)
JAVA 内存溢出案例汇总
2022-02-16 08:49:22
![](https://img.aspxhome.com/file/2023/7/61927_0s.jpg)
jdk-logging log4j logback日志系统实现机制原理介绍
2022-03-22 11:45:28
![](https://img.aspxhome.com/file/2023/7/82037_0s.png)
OpenCV实现平均背景法
2023-06-28 18:25:41
springboot用controller跳转html页面的实现
2022-08-15 06:57:51
![](https://img.aspxhome.com/file/2023/1/75711_0s.png)
详解配置spring-boot-actuator时候遇到的一些小问题
2022-03-17 17:04:08