Android自定義view實現(xiàn)太極效果實例代碼
Android自定義view實現(xiàn)太極效果實例代碼
之前一直想要個加載的loading。卻不知道用什么好,然后就想到了太極圖標(biāo),最后效果是有了,不過感覺用來做loading簡直丑到爆?。。?
實現(xiàn)效果很簡單,我們不要用什么貝塞爾曲線啥的,因為太極無非就是圓圓圓,只要畫圓就ok了。來上代碼:
因為有黑有白,所以定義2個畫筆分別為黑和白。
private void inital() { whitePaint = new Paint(); whitePaint.setAntiAlias(true); whitePaint.setColor(Color.WHITE); blackPaint = new Paint(); blackPaint.setAntiAlias(true); blackPaint.setColor(Color.BLACK); }
最后來畫3個圓就可以解決了:
protected void onDraw(Canvas canvas) { super.onDraw(canvas); Point centerPoint = new Point(width / 2, height / 2); canvas.translate(centerPoint.x, centerPoint.y); canvas.rotate(angle); //繪制兩個半圓 int radius = Math.min(bitmapwidth, bitmapheight) / 2; RectF rect = new RectF(-radius, -radius, radius, radius); //繪制區(qū)域 canvas.drawArc(rect, 90, 180, true, blackPaint); //繪制黑色半圓 canvas.drawArc(rect, -90, 180, true, whitePaint); //繪制白色半圓 //繪制兩個小圓 int smallRadius = radius / 2; canvas.drawCircle(0, -smallRadius, smallRadius, blackPaint); canvas.drawCircle(0, smallRadius, smallRadius, whitePaint); //繪制魚眼 canvas.drawCircle(0, -smallRadius, smallRadius / 4, whitePaint); canvas.drawCircle(0, smallRadius, smallRadius / 4, blackPaint); if (load) { angle += 10; if (angle >= 360) { angle = 0; } } invalidate(); }
是不是很簡單,也就幾行代碼就解決了,一開始我還打算用貝塞爾曲線的(瘋了?。。?。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
實例講解Android應(yīng)用中自定義組合控件的方法
這篇文章主要介紹了實例講解Android應(yīng)用中自定義組合控件的方法,通過例子講解了view組合控件及自定義屬性的用法,需要的朋友可以參考下2016-04-04android 監(jiān)聽網(wǎng)絡(luò)狀態(tài)的變化及實戰(zhàn)的示例代碼
本篇文章主要介紹了android 監(jiān)聽網(wǎng)絡(luò)狀態(tài)的變化及實戰(zhàn)的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01Android DrawerLayout帶有側(cè)滑功能的布局類(1)
這篇文章主要為大家詳細(xì)介紹了Android DrawerLayout帶有側(cè)滑功能的布局類,感興趣的小伙伴們可以參考一下2016-07-07Android游戲開發(fā)實踐之人物移動地圖的平滑滾動處理
玩過rpg游戲的朋友應(yīng)該都知道RPG的游戲地圖一般都比較大 今天我和大家分享一下在RPG游戲中如何來處理超出手機屏幕大小的游戲地圖。2014-06-06Android在view.requestFocus(0)返回false的解決辦法
這篇文章主要介紹了Android在view.requestFocus(0)返回false的解決辦法,非常不錯,具有參考借鑒價值,需要的朋友參考下2016-08-08