package com.example.helloworldnn;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.view.View;

public class MyCanvas extends View{

Paint paint; //绘图

public MyCanvas(Context context) {

super(context);

// TODO Auto-generated constructor stub

paint = new Paint();

paint.setColor(Color.YELLOW);

paint.setStrokeJoin(Paint.Join.ROUND);

paint.setStrokeCap(Paint.Cap.ROUND);

paint.setStrokeWidth(3);

}

/**

* 绘制网格线

*/

protected void onDraw(Canvas canvas){

canvas.drawColor(Color.BLUE);

//canvas.drawCircle(100, 100, 90, paint);

final int width = 480; //hdpi 480x800

final int height = 800;

final int edgeWidth = 10;

final int space = 30; //长宽间隔

int vertz = 0;

int hortz = 0;

for(int i=0;i<100;i++){

canvas.drawLine(0, vertz, width, vertz, paint);

canvas.drawLine(hortz, 0, hortz, height, paint);

vertz+=space;

hortz+=space;

}

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐