How to set a clickable region for an ImageView?
Asked Answered
H

1

1

I have 2 ImageViews which have AnimationDrawable backgrounds to animate a box opening and closing when you click on it. The 2 images are slightly overlapping (the transparent area) so they can be closer together.

The problem this is causing is that I am unable to click on regions of the 1st image where the 2nd image (transparent area) is overlapping.

Is there a way to set a clickable region of an ImageView?

Headship answered 13/8, 2010 at 9:2 Comment(0)
S
2

I don't think that you can "define a clickable region on an ImageView" like you would do in HTML with a map. IMO the best you could do is draw a canvas on top of your ImageView with the same size, and give it an onClick method. Now, I don't know everything, so maybe I'm mistaken.

Satterwhite answered 13/8, 2010 at 9:6 Comment(5)
Just a thought. Can this be resolved by adding touchable views on top using addTouchables?Mastoiditis
actually, I have never used this method and don't see exactly what it does, so maybe you're right. Have you tried it?Satterwhite
haven't had a chance. could not find any examples either.Mastoiditis
That's what I thought too ;) I'll have a look at the source code of this method and come back later.Satterwhite
Thanks - I used your original idea to create a clickable View overlaying the animating box. It was useful for me anyway as I'm animating the box + something popping out of the box so I added the box and the object as tags to the clickable view and onclick, I just got the 2 tagged objects out of the view and animated them. Still interested in the addTouchables solution so please let me know if it works.Headship

© 2022 - 2024 — McMap. All rights reserved.