画图形的代码自己记录一下
package com.example.lesson32_canvas; import android.R.color; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //引用 setContentView(new MyView(this)); } //声明画笔 public Paint paint = new Paint(); //创建View public class MyView extends View { public MyView(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); //设置画布背景颜色(白色) canvas.drawColor(0xffffffff); //保存当前图形的一个可编辑或一个剪辑的状态 canvas.save(); paint.setColor(Color.RED); // canvas.drawRect(0,0,100,50, paint); canvas.drawCircle(50, 40, 40, paint); //释放资源 canvas.restore(); } } }