---
title: "Android 中ShapeDrawable的使用"
author: "evilwicker"
date: "2011-04-19T17:30:22Z"
tags: []
categories: ["移动开发"]
slug: "android-shapedrawable"
draft: false
lastmod: "2011-04-19T17:38:40Z"
id: 1008266
url: "https://evilwicker.iteye.com/blog/1008266"
---

构造方法：
ShapeDrawable();
ShapeDrawable(Shape s);
作用：
在画布上绘画一些简单的图形，并且管理图形的外观。

public class SampleView extends View {

	private ShapeDrawable mShapeDrawable = null;
	
	public SampleView(Context context) {
		super(context);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		//画背景
		canvas.drawColor(Color.WHITE);
		//画图形
		mShapeDrawable = new ShapeDrawable(new OvalShape());
		//获得画笔并且绘制图形
		mShapeDrawable.getPaint().setColor(Color.GREEN);
		//设置x,y,left,top
		mShapeDrawable.setBounds(20,60,50,80);
		//绘制图形
		mShapeDrawable.draw(canvas);
		
	}
}