码迷,mamicode.com
首页 > 其他好文 > 详细

自定义view 画圆

时间:2016-04-09 09:17:25      阅读:533      评论:0      收藏:0      [点我收藏+]

标签:

package com.exaple.day01rikao;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class Myview extends View {

	public Myview(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public Myview(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public Myview(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onDraw(Canvas canvas) {
		Paint pa = new Paint();
		Paint pa1 = new Paint();
		float wi = canvas.getWidth();
		float he = canvas.getHeight();
		pa.setColor(Color.BLACK);
		pa1.setColor(Color.WHITE);

		canvas.drawColor(Color.WHITE);
		canvas.drawCircle(wi / 2, he / 2, 60, pa);
		canvas.drawCircle(wi / 2, he / 2, 55, pa1);
		canvas.drawText("hhhhhhhhhhhhhh", wi/4, he/4, pa);
		super.onDraw(canvas);
	}

	/*
	 * @Override public boolean onTouchEvent(MotionEvent event) { wi =
	 * event.getX(); he = event.getY(); this.invalidate();
	 * 
	 * return true; }
	 */

}

 技术分享 

自定义view 画圆

标签:

原文地址:http://www.cnblogs.com/jsonfan/p/5370595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!