0

My WebView loads a web page and this web page contains some images. Are there any ways to get coordinates of these images on screen when they is clicked ?

I need the coordinates of these images because I want to play some animations when people click on them but now i'm totally stuck with getting image's location :(.

Any helps will be appreciated. Thanks so much!

Wayne
  • 6,361
  • 10
  • 46
  • 69

1 Answers1

1

Since the website is also yours, you can use a javascript bridge to determine when an image was clicked, and in combination with dispatchTouchEvent you can get the exact tap location on the screen. The steps that you could take are:

  1. monitor all tap events on the screen in the dispatchTouchEvent method of your activity
  2. save the last touch on the screen
  3. monitor image clicks using your javascript interface
  4. when an image is clicked, use the last saved tap location you got in dispatchTouchEvent
Community
  • 1
  • 1
zrgiu
  • 6,200
  • 1
  • 33
  • 35
  • Thanks you for your fast reply but all I want is exact coordinates of image on screen, this means the top-left coord and the width, height of image. In additions, to determine if image was click, i use image hyperlink, for example `myownscheme://example.com/image.jpg` and just catch this on `shouldOverrideUrlLoading` – Wayne Mar 13 '12 at 06:55
  • you're still stuck with javascript though, along with a javascript bridge (if you want to do android stuff in java code). You can get the dimensions using the `width` and `height` parameters of the img node in js, as well as the click coordinates with the `event` parameter – zrgiu Mar 13 '12 at 06:59
  • Sorry if I misunderstood you (English is not my mother tongue), but I don't want the click coordinates, I want the coordinates of image on screen (top-left position). JS can do this? ( – Wayne Mar 13 '12 at 07:11
  • 1
    yes, check out this SO question and answer(it also works for images): http://stackoverflow.com/questions/288699/get-the-position-of-a-div-span-tag – zrgiu Mar 13 '12 at 07:13