Android實(shí)現(xiàn)仿微軟系統(tǒng)加載動(dòng)畫(huà)效果
效果圖:
實(shí)現(xiàn)步驟:
- 初始化五個(gè)圓球分別設(shè)置中心點(diǎn),方便畫(huà)圓
- 利用ValueAnimator的值變化來(lái)獲取旋轉(zhuǎn)角度
- onDraw來(lái)分別畫(huà)每個(gè)圓
具體代碼實(shí)現(xiàn):
1、創(chuàng)建Circle對(duì)象
package com.sjl.keeplive.track; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; public class Circle { private PointF center; private float radius; public Circle() { center = new PointF(); } /** * 設(shè)置圓球半徑 */ public void setRadius(float radius) { this.radius = radius; } /** * 設(shè)置中心點(diǎn) * * @param x * @param y */ public void setCenter(float x, float y) { center.set(x, y); } public void draw(Canvas canvas, Paint paint) { canvas.drawCircle(center.x,center.y,radius,paint); } }
2、自定義MinSoftLoadingView實(shí)現(xiàn)代碼
package com.sjl.keeplive.track; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.PointF; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; public class MinSoftLoadingView extends View { private int circleCount = 5; private Circle[] circles; private Paint paint; private int width; private int height; private PointF center; private float circleRadius; private float[] rotates; private float roateRadius; public MinSoftLoadingView(Context context) { this(context, null); } public MinSoftLoadingView(Context context, @Nullable AttributeSet attrs) { this(context, attrs, 0); } public MinSoftLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.WHITE); //每個(gè)點(diǎn)旋轉(zhuǎn)的角度 rotates = new float[circleCount]; } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); width = getWidth(); height = getHeight(); center = new PointF(width / 2.0f, height / 2.0f); //旋轉(zhuǎn)掃描半徑 roateRadius = Math.min(width, height); //圓球最大的那個(gè)半徑 circleRadius = roateRadius / 10.0f; initCircle(); } /** * 初始化5個(gè)圓球 */ private void initCircle() { circles = new Circle[circleCount]; for (int i = 0; i < circleCount; i++) { circles[i] = new Circle(); circles[i].setCenter(center.x, center.y - roateRadius / 2 + circleRadius); circles[i].setRadius(circleRadius - circleRadius * i / 5); } //開(kāi)始執(zhí)行動(dòng)畫(huà) startAnimation(); } private void startAnimation() { for (int i = 0; i < circleCount; i++) { final int index = i; ValueAnimator animator = ValueAnimator.ofFloat(0, 360); animator.setRepeatCount(ValueAnimator.INFINITE);//重復(fù) animator.setDuration(2000); animator.setStartDelay(index * 100); //每一個(gè)隨后的延遲時(shí)間 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { rotates[index] = (float) animation.getAnimatedValue(); invalidate(); } }); animator.start(); } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); for (int i = 0; i < circleCount; i++) { canvas.save(); canvas.rotate(rotates[i], center.x, center.y); circles[i].draw(canvas, paint); canvas.restore(); } } }
3、布局文件中使用
<com.sjl.keeplive.track.MinSoftLoadingView android:layout_width="60dp" android:layout_height="60dp" android:layout_gravity="center"/>
核心思想就是讓每個(gè)球出發(fā)的時(shí)間不同,這樣每個(gè)球鎖旋轉(zhuǎn)的位置也不同,就形成了一種視覺(jué)差!如果把* animator.setStartDelay(index * 100)*的時(shí)間改的大一些就可以看得更明顯了!
以上就是Android實(shí)現(xiàn)仿微軟系統(tǒng)加載動(dòng)畫(huà)效果的詳細(xì)內(nèi)容,更多關(guān)于Android 微軟系統(tǒng)加載動(dòng)畫(huà)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Android自定義加載圈動(dòng)畫(huà)效果
- Android實(shí)現(xiàn)笑臉進(jìn)度加載動(dòng)畫(huà)
- android實(shí)現(xiàn)加載動(dòng)畫(huà)對(duì)話框
- Android 自定義加載動(dòng)畫(huà)Dialog彈窗效果的示例代碼
- android自定義波浪加載動(dòng)畫(huà)的實(shí)現(xiàn)代碼
- Android仿視頻加載旋轉(zhuǎn)小球動(dòng)畫(huà)效果的實(shí)例代碼
- Android 使用 Path 實(shí)現(xiàn)搜索動(dòng)態(tài)加載動(dòng)畫(huà)效果
- Android使用View Animation實(shí)現(xiàn)動(dòng)畫(huà)加載界面
- Android使用lottie加載json動(dòng)畫(huà)的示例代碼
- Android實(shí)現(xiàn)仿iOS菊花加載圈動(dòng)畫(huà)效果
相關(guān)文章
內(nèi)存泄漏檢測(cè)工具LeakCanary源碼解析
這篇文章主要為大家介紹了內(nèi)存泄漏檢測(cè)工具LeakCanary源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Android切換前后臺(tái)點(diǎn)擊通知進(jìn)入當(dāng)前頁(yè)面
這篇文章主要介紹了Android切換前后臺(tái)點(diǎn)擊通知進(jìn)入當(dāng)前頁(yè)面,主要講述當(dāng)App退出到后臺(tái)的后,怎么點(diǎn)擊通知回到原來(lái)按下HOME鍵之前的前臺(tái)頁(yè)面,需要的朋友可以參考下2023-03-03Android Jetpack組件之ViewModel使用詳解
Android中的ViewModel是一個(gè)可以用來(lái)存儲(chǔ)UI相關(guān)的數(shù)據(jù)的類(lèi)。ViewModel的生命周期會(huì)比創(chuàng)建它的Activity、Fragment的生命周期長(zhǎng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-04-04Android仿硬幣轉(zhuǎn)動(dòng)微信紅包動(dòng)畫(huà)效果
項(xiàng)目需要研究了一下微信紅包動(dòng)畫(huà),即硬幣轉(zhuǎn)動(dòng)的效果,原理其實(shí)就是三張不同角度的圖片利用AnimationDrawable幀動(dòng)畫(huà)進(jìn)行播放。下面通過(guò)本文給大家分享Android仿微信紅包動(dòng)畫(huà)效果,感興趣的朋友一起看看吧2017-12-12Android實(shí)現(xiàn)復(fù)制Assets文件到SD卡
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)復(fù)制Assets文件到SD卡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12Android?Studio實(shí)現(xiàn)智能聊天
這篇文章主要為大家詳細(xì)介紹了Android?Studio實(shí)現(xiàn)智能聊天,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07Android tabLayout+recyclerView實(shí)現(xiàn)錨點(diǎn)定位的示例
這篇文章主要介紹了Android tabLayout+recyclerView實(shí)現(xiàn)錨點(diǎn)定位的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08Flutter實(shí)現(xiàn)倒計(jì)時(shí)功能
這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)倒計(jì)時(shí)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03