Placing touch areas on an image that is drag, pinch zoom capable
I'm looking for a way to place touchable hotspots on an image. The image (picture a desk phone with keypad, speaker button, hold, etc) is in a Framelayout wrapped within a RelativeLayout, and has a few buttons along the bottom. I need the image to be dragable, pinch/zoom-able, and have implemented that successfully following this article:
http://www.zdnet.com/b开发者_StackOverflow社区log/burnette/how-to-use-multi-touch-in-android-2/1747?tag=mantle_skin;contentI've tried a few ways to embed hotspots including this technique (from ip332): http://groups.google.com/group/android-developers/browse_thread/thread/ffabb722efac62b2
that uses points to determine the hotspots. But with the drag & zoom feature, this obviously doesn't work because the points change whenever you drag or zoom. I could try to manually adjust all of my hotspot locations within the onTouch method whenever a motion is detected, but that seems a bit too hairy to me.In a dream world, I'd like to somehow embed ImageButtons within the image and have the image and ImageButtons scale and move with the drag & zoom. ImageButtons would also allow the ability to give feedback (e.g. color change, etc) when a hotspot is pressed.
Any suggestions?
You can listen for touch
events, save the touched location's x/y coordinates on ACTION_DOWN
and compare those with the ones on ACTION_UP
. If they're really close to each other and the time interval is less than X miliseconds, you have a click.
I had the same issue, I solved it by having my hotspots defined with XY coords, which I then translated based on the zoom and scale transformations of the parent image. Using these transformed XY coords, I then painted a bitmap, and if the user touched within the XY area (+/- a boundary size), and didn't move their finger more than a certain threshold - then I took that as a 'click'
Make sense?
精彩评论