当前位置:网站首页>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);
}
}
边栏推荐
- 几行事务代码,让我赔了16万
- 5、【WebGIS实战】软件操作篇——服务发布及权限管理
- Clion and C language
- CX5120控制汇川IS620N伺服报错E15解决方案
- C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
- POI exports excel and displays hierarchically according to parent-child nodes
- EtherCAT简介
- Go tool cli for command line implementation
- 服务器渲染技术jsp
- 多元线性回归
猜你喜欢

不用加减乘除实现加法

How to verify whether the contents of two files are the same

Depth first traversal of C implementation Diagram -- non recursive code

C#实现图的深度优先遍历--非递归代码
![[us match preparation] complete introduction to word editing formula](/img/e4/5ef19d52cc4ece518e79bf10667ef4.jpg)
[us match preparation] complete introduction to word editing formula

Redis高效点赞与取消功能

Cookie&Session

MySQL knowledge points

第03章_用戶與權限管理

Elk elegant management server log
随机推荐
Install vcenter6.7 [vcsa6.7 (vCenter server appliance 6.7)]
E15 solution for cx5120 controlling Huichuan is620n servo error
实战 ELK 优雅管理服务器日志
Thread data sharing and security -threadlocal
Promise中finally的用法
8 pits of redis distributed lock
How the network is connected: Chapter 2 (Part 2) packet receiving and sending operations between IP and Ethernet
[linear DP] longest common subsequence
数据库中COMMENT关键字的使用
Design practice of current limiting components
Cookie&Session
multiple linear regression
Introduction to webrtc concept -- an article on understanding source, track, sink and mediastream
Pytest -- plug-in writing
Introduction to EtherCAT
go实现命令行的工具cli
[exsi] transfer files between hosts
Elk elegant management server log
Introduction and installation of Solr
POI exports excel and displays hierarchically according to parent-child nodes