Android自定義view實現(xiàn)太極效果實例代碼
Android自定義view實現(xiàn)太極效果實例代碼
之前一直想要個加載的loading。卻不知道用什么好,然后就想到了太極圖標,最后效果是有了,不過感覺用來做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實現(xiàn)拍照及圖片裁剪(6.0以上權(quán)限處理及7.0以上文件管理)
本篇文章主要介紹了Android實現(xiàn)拍照及圖片裁剪(6.0以上權(quán)限處理及7.0以上文件管理),非常具有實用價值,需要的朋友可以參考下2017-10-10
Android開發(fā)筆記之:深入理解Cursor相關(guān)的性能問題
本篇文章是對Android中Cursor相關(guān)的性能問題進行了詳細的分析介紹,需要的朋友參考下2013-05-05
Android應(yīng)用程序轉(zhuǎn)到后臺并回到前臺判斷方法
這篇文章主要介紹了Android應(yīng)用程序轉(zhuǎn)到后臺并回到前臺判斷方法的相關(guān)資料,需要的朋友可以參考下2016-11-11
Android開發(fā)之自定義星星評分控件RatingBar用法示例
這篇文章主要介紹了Android開發(fā)之自定義星星評分控件RatingBar用法,結(jié)合具體實例形式分析了Android自定義評分控件的具體實現(xiàn)步驟以及功能、布局相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
Android編程開發(fā)之EditText中inputType屬性小結(jié)
這篇文章主要介紹了Android編程開發(fā)之EditText中inputType屬性用法,分析說明了Android中EditText的inputType屬性具體含義與使用技巧,需要的朋友可以參考下2016-01-01

