Android 自定义View:实现windows10加载圈圈

自从windows10出来之后就被他华丽的外表所欺骗了,毅然决然地升级了系统,虽然很多bug但体验很舒服,每次开机看到那个加载动画觉得挺不错,突发奇想的就想写一个~

效果图


主要是以下两段代码的实现

圆圈动画

privateValueAnimatorgetCircleData(float[] startCoordinate, float[] RCoordinate, intdelay) {

floatx1 = startCoordinate[0];

floaty1 = startCoordinate[1];

floatx0 = RCoordinate[0];

floaty0 = RCoordinate[1];

//        Log.i(TAG, "getCircleData x y: " + x1+"  ,"+y1+"  x0  "+x0+ " y0  "+y0);

circleR= (float) Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));

floatparam = (float) (Math.abs(y1 - y0) /circleR);

if(param < -1.0) {

param = -1.0f;

}else if(param >1.0) {

param =1.0f;

}

floata = (float) Math.asin(param);

if(x1 >= x0 && y1 >= y0) {

a = a;

}else if(x1 < x0 && y1 >= y0) {

a =pi- a;

}else if(x1 < x0 && y1 < y0) {

a = a +pi;

}else{

a =2*pi- a;

}

ValueAnimator circleAnimator = ValueAnimator.ofFloat(a,a +2*pi);

circleAnimator.setDuration(1800);

circleAnimator.setInterpolator(slowToQuick);

circleAnimator.setStartDelay(delay);

returncircleAnimator;

}

获取同一个圆上,间隔固定角度的点坐标

private float[]onCiecleCoordinate(floatangle, float[] start, float[] center) {

floatx1 = start[0];

floaty1 = start[1];

floatx0 = center[0];

floaty0 = center[1];

floatR = (float) Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));

floatparam = (float) (Math.abs(y1 - y0) / R);

if(param < -1.0) {

param = -1.0f;

}else if(param >1.0) {

param =1.0f;

}

floata = (float) Math.asin(param);

if(x1 >= x0 && y1 >= y0) {

a = a;

}else if(x1 < x0 && y1 >= y0) {

a =pi- a;

}else if(x1 < x0 && y1 < y0) {

a = a +pi;

}else{

a =2*pi- a;

}

floatx = (float) (center[0] + R * Math.cos(a + angle));

floaty = (float) (center[1] + R * Math.sin(a + angle));

return new float[]{x,y};

}

如何使用

<com.loper7.base.widget.WindowsLoad

android:layout_width="35dp"

android:layout_height="35dp"/>

类文件链接

类文件链接 

喜欢的话直接下载放进工程即可使用。

其实没什么难度,实现方式也简单,我居然懒惰到循环都懒得写了!见谅

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容