Reputation: 36058
In my Android application I will retrieve data from a server where some coordinates will be returned back. Then I use these coordinates to create lines and draw them in the view.
I want a line rendered in different manners. For example: line rendering
The line at the top is the original line, and I want it rendered as the shapes at the below.
And there are some lines which intersect with each other. Then the intersection may be rendered as follows:
The manner of intersection rendering at the left is what I want.
So I wonder whether the Android graphics api supports these kinds of operations?
Upvotes: 4
Views: 691
Reputation: 10203
If you're using the Android Canvas to do this drawing your path twice, with a different stroke size and color. Here's an example which 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);
Upvotes: 2