0

I have a RelativeLayout with a thin red frame background and a (mostly transparent) ImageView as a child. Their sizes are equal:

enter image description here

On screen it looks as follows:

enter image description here

When user presses this compound object, I want to change frame's color to green:

enter image description here

I set RelativeLayout's background to a StateListDrawable that switches red to green. It works fine until I add a child ImageView (representing blue letter "A") to the RelativeLayout. This ImageView intercepts input touches and therefeore blocks input. I tried to call

imageView.setEnabled(false);
imageView.setFocusable(false);
relativeLayout.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);

but nothing helped.

How do I make an ImageView "transparent" to input events?

Nick
  • 2,905
  • 8
  • 55
  • 100
  • Easiest way: set an OnClickListener to your View and in onCLick() toggle the color change. – Thommy Jan 18 '13 at 12:17
  • @Nick http://stackoverflow.com/questions/4415528/how-to-pass-the-onclick-event-to-its-parent-on-android might be helpful to you. Nicely done question by the way. – Audrius Jan 18 '13 at 12:18

1 Answers1

2

Set an OnTouchListener to the ImageView that returns false in any case. This way the touch event wont be consumed and gets passed on to the next Listener.

pumpkee
  • 3,347
  • 3
  • 26
  • 34