android开发过程中自定义动画加载进度条实现过程

本文记录了在Android开发中创建自定义动画加载进度条的步骤。首先,创建了anim文件夹下的animation.xml配置文件,然后在Activity中进行调用以显示动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开发过程中需要自定义开发一个加载进度条显示,这里记录下来方便以后查找。

首先:定义一个anim文件夹下的animation.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/progress_1" android:duration="200"/>
    <item android:drawable="@drawable/progress_2" android:duration="200"/>
    <item android:drawable="@drawable/progress_3" android:duration="200"/>
    <item android:drawable="@drawable/progress_4" android:duration="200"/>
    <item android:drawable="@drawable/progress_5" android:duration="200"/>
    <item android:drawable="@drawable/progress_6" android:duration="200"/>
    <item android:drawable="@drawable/progress_7" android:duration="200"/>
    <item android:drawable="@drawable/progress_8" android:duration="200"/>
</animation-list>

其中,animation-list是加载过程中的动画列表。item标签是其中的图片资源文件,其中android:duration="200"表示动画持续的时间,时间以毫秒为单位。

定义好之后,便可以在Activity中进行调用。

ImageView imageView = (ImageView) findViewById(R.id.loadingImageView);
imageView.setBackgroundResource(R.drawable.progress_circular);
AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
if(hasFocus) {
  frameAnimation.start();
  } else {
  frameAnimation.stop();
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值