Use XML Layout to contain a simple drawing
I would like to create a simple drawing (lines, circles, squares, etc...) but I'm having difficulty figuring out the best way to do this. The drawing would need to be scaled to fit the display since the size is indirectl开发者_JAVA技巧y specified by the user (like in a CAD application). Also, I don't want to take up the entire display, leaving room for some controls (buttons, etc). I would pass the data to describe the drawing. Here's how I imagine it would work.
I create an XML layout that contains something that holds the drawing (ImageView, BitmapDrawable, ShapeDrawable, ...??? not sure exactly what). Then in my Activity I would load the main XML and obtain the resource for the control that holds the drawing. I would then draw to a bitmap. Once the bitmap was completed I would load it into the control that is to hold the drawing. Somewhere along this path it would be scaled to fill the entire area allocated for the drawing in the XML layout.
I don't know if my approach is the way to do this or what classes to use. I read the http://developer.android.com/guide/topics/graphics/2d-graphics.html documentation, but it's not helping me with an example. The examples I do find leave me with hints, but nothing concrete enough to do what I want, especially when it comes to scaling, using XML and/or having other controls. Also, there seems to be no good documentation on the design of the 2D drawing system in a more conceptual manner, so it makes what I read difficult to put into any useful context.
Any hints on what classes would be useful and/or a good example any other reading materials?
Thanks
A few weeks ago I wrote some documentation up for Drawables in XML, I think you'll find it pretty handy: http://idunnolol.com/android/drawables.html
In particular, you want to check out the <shape> documentation
.
You should read the tutorial series I wrote. The first one shows the typical begin with XML. In part two you learn to use the SurfaceView to draw what you need. At this point you should be able to draw lines, circles and more...
http://www.droidnova.com/playing-with-graphics-in-android-part-i,147.html
精彩评论