I created a drawing using different paths, but how can I move the entire drawing? How can I selected and move it around? Here is the main part of my onDraw method:
Path theSymbol = new Path();
theSymbol.moveTo(0.0F, 0.0F);
theSymbol.lineTo(0.0F, 50.0F);
theSymbol.lineTo(16.666666F, 58.333332F);
theSymbol.lineTo(-16.666666F, 75.0F);
theSymbol.lineTo(16.666666F, 91.666664F);
theSymbol.lineTo(-16.666666F, 108.33333F);
theSymbol.lineTo(16.666666F, 124.99999F);
theSymbol.lineTo(-16.666666F, 141.66666F);
theSymbol.lineTo(0.0F, 150.0F);
theSymbol.lineTo(0.0F, 200.0F);
theSymbol.offset(100.0F, 20.0F);
canvas.drawPath(theSymbol, paint);
That’s how I draw a resistor to the screen (It works). Now I want some way of making all those paths be an object, something that I can select and move.
I have been looking at some projects like Sriracha, but I can’t find how they are doing their element drawings.
I have also searched countless times, but all I get is “moving something on a path”. Maibe I am searching for the wrong thing or this is not the way to do this kind of things.
I wold really appreciate if someone can point me in the right direction.
Put this drawing code into the
onDraw()method of a customViewsubclass. Then you can place your drawings around the screen however you like using layouts, animations, and other transformations just like any other view in the framework. Something like:For more information about creating custom views, check out the SDK docs.
HTH