Android: How to propagate click event to LinearLayout childs and change their drawable

后端 未结 5 1733
灰色年华
灰色年华 2021-01-31 10:05

I would like to create a linear layout which would behave similarly to ImageButton.



        
5条回答
  •  借酒劲吻你
    2021-01-31 10:41

    In my case, no one of the other solutions works!

    I finally had to use OnTouchListener as explained here, capturing the event when the user clicks in the parent view, and removing all childs OnClickListener.

    So the idea is, delegate the click behavior to the parent, and notify the child that is really clicked, if you want to propagate the event. ¡¡That's what we are looking for!!

    Then, we need to check which child has been clicked. You can find a reference here to know how it´s done. But the idea is basiclly getting the area of the child, and asking for who contains the clicked coordinates, to perform his action (or not).

提交回复
热议问题