Android line crossing display

In my Android application, I get data from a server on which some coordinates will be returned. Then I use these coordinates to create lines and draw them in the view.

I want the line to be displayed differently. For example: rendering strings

enter image description here

The line at the top is the original line, and I want it to appear as shapes below.

And there are several lines that intersect with each other. Then the intersection can be performed as follows:

enter image description here

The way to display the intersection on the left is what I want.

So, I am wondering if the Android graphics api supports these operations?

+4
source share
1 answer

If you use Android Canvas for this, draw your path twice, with a different size and stroke color. Here is an example that creates a bitmap with an image similar to what you want:

// Creates a 256*256 px bitmap Bitmap bitmap = Bitmap.createBitmap(256, 256, Config.ARGB_8888); // creates a Canvas which draws on the Bitmap Canvas c = new Canvas(bitmap); // Creates a path (draw an X) Path path = new Path(); path.moveTo(64, 64); path.lineTo(192, 192); path.moveTo(64, 192); path.lineTo(192, 64); // the Paint to draw the path Paint paint = new Paint(); paint.setStyle(Style.STROKE); // First pass : draws the "outer" border in red paint.setColor(Color.argb(255, 255, 0, 0)); paint.setStrokeWidth(40); c.drawPath(path, paint); // Second pass : draws the inner border in pink paint.setColor(Color.argb(255, 255, 192, 192)); paint.setStrokeWidth(30); c.drawPath(path, paint); // Use the bitmap in the layout ((ImageView) findViewById(R.id.image1)).setImageBitmap(bitmap); 
+2
source

All Articles