欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義view實現(xiàn)太極效果實例代碼

 更新時間:2017年05月08日 14:24:21   投稿:lqh  
這篇文章主要介紹了Android自定義view實現(xiàn)太極效果實例代碼的相關(guā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)文章

最新評論