Android 绘制太极图实例详解

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

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

时间: 2024-09-30 21:34:17

Android 绘制太极图实例详解的相关文章

Android ProgressDialog的实例详解

Android ProgressDialog的实例详解 当自己做一些耗时操作时,希望给用户一些提示信息,告诉用户正在进行耗时操作,这时就可以用到ProgressDialog. 1.新建一个全局变量ProgressDialog private ProgressDialog mDialog; 2.设置ProgressDialog的相关参数: progressDialog = new ProgressDialog( ProgressDialogActivity.this); //设置进度条风格,风格为

Android xml解析实例详解

Android  xml解析实例详解 实现效果图: XmlActivity package com.Android.xiong.gridlayoutTest; import android.app.Activity; import android.content.res.XmlResourceParser; import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; impo

Android Dialog 动画实例详解

Android Dialog 动画实例详解 动画描述: 动画与底部菜单一样出现和消失 制作过程: 1. 创建两个动画文件 window_in.xml: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration=&

Android编程单元测试实例详解(附源码)_Android

本文实例讲述了Android编程单元测试.分享给大家供大家参考,具体如下: 完整实例代码代码点击此处本站下载. 本文是在上一篇文章<java编程之单元测试(Junit)实例分析>的基础上继续讲解android的单元测试,android源码中引入了java单元测试的框架(android源码目录:libcore\junit\src\main\java\junit\framework中可见),然后在java单元测试框架的基础上扩展属于android自己的测试框架.android具体框架类的关系图如下

Android clipChildren属性实例详解_Android

前言  前几天有在微博上推荐过一个博客,看他文章时发现了这个属性.有些属性不常用,但需要的时候非常有用,于是做了个例子,正好项目用到,与大家分享一下.  正文  一.效果图   看到这个图时你可以先想想如果是你,你怎么实现这个效果.马上想到用RelativeLayout?NO,NO,NO,,,  二.实现代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&qu

安卓Android Context类实例详解_Android

1.例如下面的代码片段,Toast类的第一个参数接受一个Context对象: @Override protected Dialog onCreateDialog(int id) { switch (id) { case 0: Builder builder = new AlertDialog.Builder(this); builder.setIcon(R.drawable.ic_launcher); builder.setTitle("This is a dialog with some si

Android 调用WCF实例详解_Android

Android 调用WCF实例 1. 构建服务端程序 using System.ServiceModel; namespace yournamespace { [ServiceContract(Name = "HelloService", Namespace = "http://www.master.haku")] public interface IHello { [OperationContract] string SayHello(); } } namespa

Android 图片缩放实例详解_Android

本文实现Android中的图片的缩放效果 首先设计布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_par

Android 调用WCF实例详解

Android 调用WCF实例 1. 构建服务端程序 using System.ServiceModel; namespace yournamespace { [ServiceContract(Name = "HelloService", Namespace = "http://www.master.haku")] public interface IHello { [OperationContract] string SayHello(); } } namespa