【Android进度条】三种方式实现自定义圆形进度条ProgressBar
Android 实现 方式 自定义 三种 进度条 圆形 ProgressBar
2023-09-11 14:17:57 时间
一、通过动画实现
定义res/anim/loading.xml如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <animation-list android:oneshot="false"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:duration="150" android:drawable="@drawable/loading_01" />
- <item android:duration="150" android:drawable="@drawable/loading_02" />
- <item android:duration="150" android:drawable="@drawable/loading_03" />
- <item android:duration="150" android:drawable="@drawable/loading_04" />
- <item android:duration="150" android:drawable="@drawable/loading_05" />
- <item android:duration="150" android:drawable="@drawable/loading_06" />
- <item android:duration="150" android:drawable="@drawable/loading_07" />
- </animation-list>
二、通过自定义颜色实现
定义res/drawable/progress_small.xml如下:
- <?xml version="1.0" encoding="utf-8"?>
- <rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:fromDegrees="0"
- android:pivotX="50%"
- android:pivotY="50%"
- android:toDegrees="360" >
- <shape
- android:innerRadiusRatio="3"
- android:shape="ring"
- android:thicknessRatio="8"
- android:useLevel="false" >
- <gradient
- android:centerColor="#FFFFFF"
- android:centerY="0.50"
- android:endColor="#1E90FF"
- android:startColor="#000000"
- android:type="sweep"
- android:useLevel="false" />
- </shape>
- </rotate>
三、使用一张图片进行自定义
定义res/drawable/progress_small.xml如下:
- <rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/spinner_black_16"
- android:pivotX="50%"
- android:pivotY="50%"
- android:fromDegrees="0"
- android:toDegrees="360" />
使用方法都一样, 如下:
- <ProgressBar
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:indeterminateDrawable="@drawable/progress_small"/>
也可以根据需要通过设置style来设置其大小! 一般只有使用默认的ProgrressBar的时候采用。对于上述三种自定义的方式,建议修改直接修改图片大小,或者shape;
- <ProgressBar
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- style="?android:attr/progressBarStyleSmall"
- android:indeterminateDrawable="@drawable/progress_small"/>
设置成progressBarStyleSmall后,图标变小。
设置成progressBarStyleLarge后,图标变大
参考: http://www.eoeandroid.com/forum.php?mod=viewthread&tid=76872
相关文章
- Android之QQ授权登录获取用户信息
- Android锁屏或灭屏状态下,高速按两次音量下键实现抓拍功能(1.2Framework层使用startService形式实现)
- Android开发之实现锁屏功能
- Android实现RecyclerView分组显示功能完整示例(自定义组头和Item布局)
- Android实现推送方式解决方案
- 《Android游戏开发详解》一1.2 数据类型
- 《Android 源码设计模式解析与实战》——第2章,第2.6节单例模式的其他实现方式
- Android数据绑定框架DataBinding用法
- 基于Node.JS+MongoDB+Android实现新闻聚合网站【100010390】
- Android性能优化之使用线程池处理异步任务
- Android中实现整个视图切换的左右滑动效果
- 保持Service不被Kill掉的方法--双Service守护 && Android实现双进程守护
- [yueqian_scut]蓝牙防丢器原理、实现与Android BLE接口编程
- android httpClient 支持HTTPS的访问方式
- Android使用GridView实现日历功能(详细代码)
- Android APK方式换肤实现原理
- android UI进阶之用ViewPager实现欢迎引导页面
- Android 换肤功能的实现(Apk插件方式)
- android 开发上传图片遇到返回 FileNotFoundException
- Android平台上使用MQTT协议实现消息推送功能
- Android 串口通信基于licheedev和android-serialport两种方案实现附Demo
- 【Android JNI】JNIEnv和JavaVM的区别
- Android的TextView与Html相结合的用法
- Android实现左右滑动指引效果
- Android学习之菜单实现
- Android学习之关于实现子线程需要掌握的两种方式
- Android学习之界面切换的两种效果实现(直接跳转,滑动切换)
- 赵雅智_android多线程下载带进度条
- Unity Vuforia 之 简单实现Vuforia调用Android设备外接摄像头camera实现AR
- Android toolbar详解