欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 绘制太极图实例详解

程序员文章站 2024-02-25 20:00:51
android 绘制太极图 绘制一个太极图实现代码: package com.jackie.taijicircle; import android.c...

android 绘制太极图

绘制一个太极图实现代码:

package com.jackie.taijicircle; 
 
import android.content.context; 
import android.graphics.canvas; 
import android.graphics.color; 
import android.graphics.paint; 
import android.graphics.rectf; 
import android.util.attributeset; 
import android.view.view; 
 
/** 
 * created by administrator on 2016/11/14. 
 */ 
 
public class taijicircleview extends view { 
  private paint mpaint; 
  private int mwidth; 
 
  public taijicircleview(context context) { 
    this(context, null); 
  } 
 
  public taijicircleview(context context, attributeset attrs) { 
    this(context, attrs, 0); 
  } 
 
  public taijicircleview(context context, attributeset attrs, int defstyleattr) { 
    super(context, attrs, defstyleattr); 
 
    initpaint(); 
  } 
 
  private void initpaint() { 
    mpaint = new paint(); 
    mpaint.setcolor(color.black); 
    mpaint.setstrokewidth(5); 
    mpaint.setantialias(true); 
    mpaint.setdither(true); 
    mpaint.setstyle(paint.style.fill); 
  } 
 
  private void drawcircle(canvas canvas) { 
    mpaint.setcolor(color.black); 
    //x轴正轴为0° 
//    canvas.drawarc(new rectf(0, 0, width, width), 90, 180, true, mpaint); 
    canvas.drawarc(new rectf(0, 0, mwidth, mwidth), 270, -180, true, mpaint); 
 
    mpaint.setcolor(color.white); 
//    canvas.drawarc(new rectf(0, 0, width, width), 90, -180, true, mpaint); 
    canvas.drawarc(new rectf(0, 0, mwidth, mwidth), 270, 180, true, mpaint); 
  } 
 
  private void drawhalfcircle(canvas canvas) { 
    mpaint.setcolor(color.black); 
    canvas.drawarc(new rectf(mwidth / 4, 0, mwidth / 2 + mwidth / 4, mwidth / 2), 
        270, 180, true, mpaint); 
 
    mpaint.setcolor(color.white); 
    canvas.drawarc(new rectf(mwidth / 4, mwidth / 2, mwidth / 2 + mwidth / 4, mwidth), 
        270, -180, true, mpaint); 
  } 
 
  private void drawsmallcircle(canvas canvas) { 
    mpaint.setcolor(color.black); 
    canvas.drawcircle(mwidth / 2, mwidth * 3 / 4, 20, mpaint); 
 
    mpaint.setcolor(color.white); 
    canvas.drawcircle(mwidth / 2, mwidth / 4, 20, mpaint); 
  } 
 
  @override 
  protected void ondraw(canvas canvas) { 
    super.ondraw(canvas); 
 
    mwidth = math.min(getwidth(), getheight()); 
    drawcircle(canvas); 
    drawhalfcircle(canvas); 
    drawsmallcircle(canvas); 
  } 
} 

Android 绘制太极图实例详解

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!