I am trying to develop a map(basically a static image) in ANDROID where I can show different items(drawn in the map itself)
I am trying to develop a map(basically a static image) in ANDROID where I can show different items(drawn in the map itself). How can I do that. I've tried different approaches. The map is basically a s开发者_Python百科tatic image. Please help!
More details on what you're trying to do would help to answer this question correctly. What methods have you tried already?
- Are you trying to just draw static images overlaid each other in a view?
- Are you trying to draw an actual geographic map with a
MapView
or something along those lines?
If you're trying to draw an image over another, you can do it in a number of ways.
- You could use a
RelativeLayout
to assign absolute positions your overlay images (most likely each in the form of anImageView
). Here's a good SO answer that covers assigning absolute positions to children in an RelativeLayout: Set the absolute position of a view - You could load the base image (your map) and the overlays into
Bitmap
objects. Then, using aCanvas
object you could draw them in specified locations. Look at the variousCanvas.drawBitmap()
functions to see your options on specifying the position of theBitmap
you are drawing. You could also draw shapes instead of images using thedrawRect()
,drawRoundRect()
,drawLine()
, ordrawOval()
methods. There are other options as well. Read theCanvas
documentation.
Otherwise, if you're trying to draw a movable map of some sort, then you'll need to use a MapView
or MapActivity
. There are classes that you use to overlay images in specified locations on the map. This won't be a static image, but a movable map along with the overlays that stay in the specified location. You'll use the ItemizedOverlay
class to act as a data structure to store your actual overlay images (wrapped in the OverlayItem
class).
This is a great tutorial that goes into depth about what I'm talking about: http://developer.android.com/guide/tutorials/views/hello-mapview.html
精彩评论