自定义加载动画的两种实现方式
2023-03-07 09:07:44 时间
1.帧动画 方式
动画文件animation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/icon1" android:duration="150"></item>
<item android:drawable="@drawable/icon2" android:duration="150"></item>
<item android:drawable="@drawable/icon3" android:duration="150"></item>
<item android:drawable="@drawable/icon4" android:duration="150"></item>
<item android:drawable="@drawable/icon5" android:duration="150"></item>
<item android:drawable="@drawable/icon6" android:duration="150"></item>
</animation-list>
给imageView设置动画
<ImageView android:id="@+id/animationIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:src="@drawable/animation"/>
2.progressbar方式
方式一
ProgressBar
<pre name="code" class="java"><ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@anim/progress_bar_loading" />
动画 文件progressbar_bar_loading 放在values下的anim中
<?xml version="1.0" encoding="UTF-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:duration="250"
android:drawable="@drawable/progress_bar_loading_01" />
<item
android:duration="250"
android:drawable="@drawable/progress_bar_loading_02" />
<item
android:duration="250"
android:drawable="@drawable/progress_bar_loading_03" />
<item
android:duration="250"
android:drawable="@drawable/progress_bar_loading_04" />
<item
android:duration="250"
android:drawable="@drawable/progress_bar_loading_05" />
<item
android:duration="250"
android:drawable="@drawable/progress_bar_loading_06" />
<item
android:duration="250"
android:drawable="@drawable/progress_bar_loading_07" />
</animation-list>
方式二
<ProgressBar
android:id="@+id/pull_to_refresh_progress"
android:layout_width="30dip"
android:layout_height="30dip"
android:background="@drawable/all_refresh_logo"
android:indeterminate="true"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/progress_top_refresh"/>
文件progress_top_refresh
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/all_refresh"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
上传用到的两个图片 all_refresh 和 all_refresh_logo
all_refresh.png
all_refresh_logo.png
以上几种都可以实现加载动画效果 ,不过个人更加推荐progressbar方式 更加流畅。
相关文章
- 传鸿海与Vedanta拟邀请意法半导体加入在印度建晶圆厂计划
- 半导体硅片出现降价!近三年来首次!
- 光反应赖氨酸的高难度合成 | MedChemExpress
- 为应对美日荷封堵,大陆芯片制造商加紧采购相关设备
- 中国芯片中的“一代拳王”!
- 面板市场持续低迷,友达、群创一季度恐亏损超百亿新台币
- 韩媒:三星芯片业务今年上半年或将亏损10亿美元
- 产能利用率降至70%,联电1月营收同比下滑4.3%
- 基于定制的Oryon CPU内核,高通骁龙8cx Gen 4曝光
- ChatGPT爆红!谷歌发布AI聊天机器人Bard竞争!相关概念股飙涨
- 继惠普裁员6000人后,戴尔宣布裁员6650人!
- caspase-2 酶抑制剂有望治疗非酒精性脂肪肝 | MedChemExpress
- 寻找适合程序员的笔记软件
- BetterZip 5 for Mac(苹果专用解压缩软件) v5.3中文注册版
- 寻根究底,为什么Docker中的Alpine Linux镜像能这么小
- 新型 RORγt 小分子反向激动剂 | MedChemExpress
- 为什么检测人工智能生成的文本如此困难
- 干货分享-Adobe Audition音频时间锁定如何设置au音频时间锁定设置方法(附安装包)
- 挑战全网最快注册使用 ChatGPT!
- ERC-20 token 支付手续费源码解析