Reputation: 7958
Is it possible to create a composite XML consisting of a combination of shapes? Essentially I want to create an arrow using xml shapes -- is it possible?
If so, what's the best approach?
Upvotes: 1
Views: 430
Reputation: 10447
I'm assuming you're drawing that shape on a Canvas. You can do it in XML but it would become pretty hard to maintain.
Here is a simpler solution in Java code
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setColor(BLACK);
Path path = new Path();
path.moveTo(0, -10);
path.lineTo(5, 0);
path.lineTo(-5, 0);
path.close();
path.offset(10, 40);
canvas.drawPath(path, paint);
path.offset(50, 100);
canvas.drawPath(path, paint);
// offset is cumlative
// next draw displaces 50,100 from previous
path.offset(50, 100);
canvas.drawPath(path, paint);
If you want even more simpler solution, use a bitmap and use Matrix to rotate it in order to point in a specific direction
ImageView image = (ImageView) findViewById(R.id.bitmap_image);
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.test);
Matrix mat = new Matrix();
mat.postRotate(90);
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), mat, true);
image.setImageBitmap(bMapRotate);
Upvotes: 1