当前位置:网站首页>Pathmeasure implements loading animation
Pathmeasure implements loading animation
2022-07-01 03:26:00 【Xiao Er Li】
design sketch

PathLoadingView.java
public class PathLoadingView extends View {
private Path mPath;
private Path dest;
private Paint mPaint;
private PathMeasure mPathMeasure;
private float mLength;
private float mAnimatedValue;
public PathLoadingView(Context context) {
this(context, null);
}
public PathLoadingView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public PathLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
// Initialize brush
mPaint = new Paint();
mPaint.setColor(Color.parseColor("#FF4081"));
mPaint.setStrokeWidth(2f);
mPaint.setStyle(Paint.Style.STROKE);
mPath = new Path();
mPath.addCircle(300f, 300f, 20f, Path.Direction.CW);
// initialization PathMeasure
mPathMeasure = new PathMeasure(mPath, true);
// Path length
mLength = mPathMeasure.getLength();
dest = new Path();
// Attribute animation , Monitor animation value changes , For dynamic calculation path length
ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// Get the change of animation value
mAnimatedValue = (float) animation.getAnimatedValue();
// Trigger onDraw
invalidate();
}
});
animator.setDuration(2000);
animator.setRepeatCount(ValueAnimator.INFINITE); // Infinite loop
animator.start();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Reset before each painting dest
dest.reset();
float distance = mLength * mAnimatedValue;
// distance - 0.5*mLength < start < distance
float start = (float) (distance - (0.5 - Math.abs(mAnimatedValue - 0.5f)) * mLength);
// Intercept path Length to dest
mPathMeasure.getSegment(start,distance,dest,true);
canvas.drawPath(dest,mPaint);
}
}
边栏推荐
- How the network is connected: Chapter 2 (Part 2) packet receiving and sending operations between IP and Ethernet
- 完全背包问题
- MySQL knowledge points
- JS daily development tips (continuous update)
- Nacos
- 实战 ELK 优雅管理服务器日志
- Stop saying that you can't solve the "cross domain" problem
- 二叉树神级遍历:Morris遍历
- Basic concept and classification of sorting
- 【日常训练】1175. 质数排列
猜你喜欢

Hal library operation STM32 serial port

Filter

File upload and download

Home online shopping project
![Install vcenter6.7 [vcsa6.7 (vCenter server appliance 6.7)]](/img/83/e3c9d8eda9d5351d4c54928d3b090b.png)
Install vcenter6.7 [vcsa6.7 (vCenter server appliance 6.7)]

Introduction to EtherCAT

C#实现基于广度优先BFS求解无权图最短路径----完整程序展示

Chapitre 03 Bar _ Gestion des utilisateurs et des droits
![[linear DP] longest common subsequence](/img/47/c3172422e997009facbada929adb1a.jpg)
[linear DP] longest common subsequence

Nacos
随机推荐
ECMAScript 6.0
VMware vSphere 6.7 virtualization cloud management 12. Vcsa6.7 update vCenter server license
go实现命令行的工具cli
POI exports excel and displays hierarchically according to parent-child nodes
How the network is connected: Chapter 2 (Part 2) packet receiving and sending operations between IP and Ethernet
数据库中COMMENT关键字的使用
Redis 教程
Md5sum operation
Introduction and installation of Solr
How do spark tasks of 10W workers run? (Distributed Computing)
Data exchange JSON
力扣-两数之和
Design practice of current limiting components
leetcode 1482 猜猜看啊,这道题目怎么二分?
Learning notes for introduction to C language multithreaded programming
Introduction to webrtc concept -- an article on understanding source, track, sink and mediastream
CX5120控制汇川IS620N伺服报错E15解决方案
HTB-Lame
Cookie&Session
Error accessing URL 404