Activity.java
- public class MainActivity extends Activity {LinearLayout layout;DrawView drawView;public static Display display;int length = 10;int width, height, equal_parts_width, equal_parts_height;@SuppressLint("NewApi")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);drawView = new DrawView(this);drawView.setBackgroundColor(Color.BLACK);// setContentView(drawView);setContentView(R.layout.activity_main);layout = (LinearLayout) findViewById(R.id.load);layout.addView(drawView);display = getWindowManager().getDefaultDisplay();Point size = new Point();display.getSize(size);width = size.x;height = size.y;equal_parts_width = width / 10;equal_parts_height = height / 10;}public class DrawView extends View {Paint paint = new Paint();public DrawView(Context context) {super(context);paint.setColor(Color.WHITE);// paint.setStyle(Style.STROKE);paint.setStrokeJoin(Paint.Join.ROUND);paint.setStrokeCap(Paint.Cap.ROUND);paint.setDither(true);paint.setAntiAlias(true);}@SuppressLint("DrawAllocation")@Overridepublic void onDraw(Canvas canvas) {// float width = canvas.getWidth();// float height = canvas.getHeight();float size = width / (120 * 2); // just use 14 it's for convenience herepaint.setPathEffect(new DashPathEffect(new float[] { size, size }, 0));for (int i = 0; i < 11; i++) {canvas.drawLine(0, equal_parts_height * i, width,equal_parts_height * i, paint);canvas.drawLine(equal_parts_width * i, 0, equal_parts_width * i, height, paint);}}}}
No comments:
Post a Comment