android view画图笔记-1
1、一个简单的示例
Java代码
public class View1 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
private Paint paint;
public SampleView(Context context) {
super(context);
//创建Paint
paint = new Paint();
//设置抗锯齿效果
paint.setAntiAlias(true);
//设置画刷的颜色
paint.setColor(Color.BLUE);
}
@Override protected void onDraw(Canvas canvas) {
// canvas.drawColor(Color.WHITE);
paint.setStyle(Paint.Style.FILL);
canvas.drawRect(new RectF(10, 10, 100, 100), paint);
canvas.drawCircle(55, 145, 45, paint);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(new RectF(110, 10, 200, 100), paint);
canvas.drawCircle(155, 145, 45, paint);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawRect(new RectF(210, 10, 300, 100), paint);
canvas.drawCircle(255, 145, 45, paint);
// invalidate();
相关新闻>>
- 发表评论
-
- 最新评论 更多>>