I'm trying to create a ShapeDrawable that draws the following path:
Path path = new Path();
path.moveTo(50, 20);
path.lineTo(0, 50);
path.lineTo(50, 100);
ShapeDrawable shapeDrawable = new ShapeDrawable(new PathShape(path, someNumber ,someNumber ));
Then I put shapeDrawable as the top layer of a Layer drawable like so:
Drawable layers[] = new Drawable[2];
layers[0] = res.getDrawable(R.drawable.crawford01);
layers[1] = shapeDrawable;
LayerDrawable layerDrawable = new LayerDrawable(layers);
view.setImageDrawable(layerDrawable);
Now the problem is that the path doesn't start at (50,20) and it jumps around in ways I don't understand when you change somenumber
where shapeDrawable is constructed.
Any help or documentation that you can suggest is appreciated.
The "someNumber" attributes are actually very important when defining your
PathShape
, and are not trivial. They are the "standard" width and height of the path, essentially defining the path's bounds and relating directly to the coordinates you define your path at as specified in thePathShape
constructor here.Another important point is that the coordinates you use to define your
Path
are not absolute coordinates as far as aPathShape
is concerned, but instead is combined with the standard width and height to calculate how your shape appears when it is scaled. For example, the following twoPathShape
s are essentially identical.