7

I have a created a mapview with markers on it. Looking at this picture below:
Grandparent is a filling View
Parent is my MarkerView
Child is a marker which is clickable

Parent has clipChildren(false) and thus the children are visible.

My problem is that the children are clickable, except for the part where Child 2 is outside the Parent. Parent also has the appropriate TouchDelegate (and I also tried this for the children).

How can I make the complete child clickable?

enter image description here

HansElsen
  • 1,639
  • 5
  • 27
  • 47

3 Answers3

1

I couldn't make it work without changing the elements.
I ended up enlarging the parent and using setTranslationY for the markers to keep them in place like this:

solution

HansElsen
  • 1,639
  • 5
  • 27
  • 47
0

I had a similar issue and fixed it by setting app:elevation="XXdp" to the child.

Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
JohnTheWalker
  • 542
  • 4
  • 20
0

The reason why you can't do this is that the default implementation of ViewGroup#dispatchTouchEvent(MotionEvent ev) iterates over the children (not the grandchildren) to look for a child that are a target (is on bottom of the click event point) and can receive touch events. It will find nothing if you touched the part that it is outside the bounds of Parent, which is the only child of Grandparent. If it does not find Parent, Parent will never be able to make a look up on its children (Children 1 and Children 2) and eventually dispatch the event to Child 2.

So you either increase the size of Parent (as the acceptable answer), which is the most easy way, or you will have to override the method ViewGroup#dispatchTouchEvent(MotionEvent ev) of your Grandparent to make a more complex lookup, like looking up grandchildren too. The method is already fairly complex, if anyone finds a implementation, please share because I don't have one.

Allan Veloso
  • 5,823
  • 1
  • 38
  • 36