I would like to display an image (including scroll and zoom functionality). Additionally, I need to add some overlays to the image dynamically. The overlays are in a relationship to the content within the image.
In other words: I'd like to implement a Map with some markers, but I provide my own map material.
My main question is: How could I do this?
What I have tried so far
Questions
Is there a simple solution or approach to my problem?
What is the right way of adding and moving views at runtime in Android? (Usually, I would use a basic layout and play with the margin - would that be best practice?)
Could somebody point me to the right direction, please.
Min. API Level: 10
I would suggest extending the View
class and overriding onDraw
method.
Take a look at the Canvas API.
You'll probably have an onDraw method that looks like :
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.translate(mPosX, mPosY); //position of your actual data
canvas.scale(mScaleFactor, mScaleFactor); // zoom factor
map.draw(canvas); //you draw your map here
canvas.restore(); //go back to saved state
//for each marker you have, do the same "save - translate - scale - draw" loop
}
Since you don't need your markers to be zoomable, you'll probably wont need scale step but you need to calculate their position properly.
Depending on your # of objects etc, you may need to have a more optimized way of drawing your markers (e.g. re-drawing only changed rectangular areas). see View.invalidate(Rect)
I Think this one can help you
Refer this project Link
it Has a Automatic Scrolling of Image and Zoom a Image When you click On it.
Have you tried subclassing View and handling yourself user gestures? It is my first choice for complex behaviours as such. It should look something like this:
Plenty of material about this individual tasks on StackOverflow, let me know if you need adittional help in any of these.
Checkout this example project https://github.com/jzafrilla/AndroidImageHostpot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With