亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時(shí)間:2017年05月08日 14:24:21   投稿:lqh  
這篇文章主要介紹了Android自定義view實(shí)現(xiàn)太極效果實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下

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

之前一直想要個(gè)加載的loading。卻不知道用什么好,然后就想到了太極圖標(biāo),最后效果是有了,不過(guò)感覺(jué)用來(lái)做loading簡(jiǎn)直丑到爆?。?!

實(shí)現(xiàn)效果很簡(jiǎn)單,我們不要用什么貝塞爾曲線(xiàn)啥的,因?yàn)樘珮O無(wú)非就是圓圓圓,只要畫(huà)圓就ok了。來(lái)上代碼:

因?yàn)橛泻谟邪祝远x2個(gè)畫(huà)筆分別為黑和白。

private void inital() {
    whitePaint = new Paint();
    whitePaint.setAntiAlias(true);
    whitePaint.setColor(Color.WHITE);
    blackPaint = new Paint();
    blackPaint.setAntiAlias(true);
    blackPaint.setColor(Color.BLACK);
  }

最后來(lái)畫(huà)3個(gè)圓就可以解決了:

 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);
    //繪制兩個(gè)半圓
    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);      //繪制白色半圓
    //繪制兩個(gè)小圓
    int smallRadius = radius / 2;
    canvas.drawCircle(0, -smallRadius, smallRadius, blackPaint);
    canvas.drawCircle(0, smallRadius, smallRadius, whitePaint);
    //繪制魚(yú)眼
    canvas.drawCircle(0, -smallRadius, smallRadius / 4, whitePaint);
    canvas.drawCircle(0, smallRadius, smallRadius / 4, blackPaint);
    if (load) {
      angle += 10;
      if (angle >= 360) {
        angle = 0;
      }
    }
    invalidate();
  }

是不是很簡(jiǎn)單,也就幾行代碼就解決了,一開(kāi)始我還打算用貝塞爾曲線(xiàn)的(瘋了!?。?/p>

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論