Android 绘制太极图实例详解

所属分类: 软件编程 / Android 阅读数: 40
收藏 0 赞 0 分享

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); 
  } 
} 

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

更多精彩内容其他人还在看

Retrofit2日志拦截器的使用

这篇文章主要介绍了Retrofit2日志拦截器的使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android创建外部lib库及自定义View的图文教程

这篇文章主要给大家介绍了关于Android创建外部lib库及自定义View的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Android分享微信小程序失败的一些事小结

这篇文章主要给大家介绍了关于Android分享微信小程序失败一些事,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Android分享微信小程序技巧之图片优化

这篇文章主要给大家介绍了关于Android分享微信小程序技巧之图片优化的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Android Viewpager实现无限循环轮播图

这篇文章主要为大家详细介绍了Android Viewpager实现无限循环轮播图,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Android中的Bitmap序列化失败的解决方法

这篇文章主要介绍了Android中的Bitmap序列化失败的解决方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

Android自定义通用标题栏CustomTitleBar

这篇文章主要为大家详细介绍了Android自定义通用标题栏CustomTitleBar,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Android组合控件自定义标题栏

这篇文章主要为大家详细介绍了Android组合控件自定义标题栏,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Android自定义复合控件实现通用标题栏

这篇文章主要为大家详细介绍了Android自定义复合控件实现通用标题栏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

ExpandableListView实现简单二级列表

这篇文章主要为大家详细介绍了ExpandableListView实现简单二级列表,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享
查看更多