I have two ImageViews, iv1 and iv2, where iv2 overlaps on the iv1 with 20dp.
Now, if I tap exactly in the region where iv1 is visible, it responds to event, but if I set iv2‘s visibility to GONE or INVISIBLE and also make it’s setEnabled(false), I can see iv1 completely, but still only partial of its region (which was visible behind iv2) is responsive to tap events.
How can I make complete ImageView to be tap responsive if overlapping view is disabled or is invisible?
That’s happening because iv2 is in front of iv1. Try calling
iv1.bringToFront();. That will place iv1 in front of iv2 and it’s full area becomes tap responsive.And if later you want to change visibility of iv2 you’ll have to call
iv2.bringToFront();to make things like they were before setting iv2 invisible.If you want to place iv1 in front of iv2 from the beginning you have to put it’s definition in xml file after iv2’s. The views will be drawn in the order of their appearance in layout xml file. So the first view is on the bottom, the last is on the top.