简体   繁体   中英

android make View transparent to input

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

在此处输入图片说明

On screen it looks as follows:

在此处输入图片说明

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

在此处输入图片说明

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM