美文网首页
android绘图网格线java写法

android绘图网格线java写法

作者: babybus_hentai | 来源:发表于2016-05-25 22:01 被阅读908次

    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;
    }
    }
    }

    相关文章

      网友评论

          本文标题: android绘图网格线java写法

          本文链接:https://www.haomeiwen.com/subject/ujitdttx.html