android绘图网格线java写法

2016-05-25  本文已影响908人  babybus_hentai

package com.heal.nmm;
//引入模块
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.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.RED);
final int width = 180;
final int height = 400;
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;
}
}
}

上一篇下一篇

猜你喜欢

热点阅读