Android: Create image button with a non-clickable overlarge overlay when focused?
For a new Android project I need buttons which are 'shining' when focused or pressed, meaning a bigger image should show up on top of the first image. My pro开发者_如何学Goblem here is: The clickable area should be not as large as this overlay image.
In ASCII-Art:
+------------------------------------------+
| |
| |
| +---------------------+ |
| | Inner image, always | |
| | visible & clickable | |
| +---------------------+ |
| Overlay (image with alpha on top) |
| visible on focus or press, NOT clickable |
+------------------------------------------+
So basically there may be other items under the overlay image which should still be fully accessible, e.g. by clicking & dragging.
Do you know how I may solve this in Android? A XML layout solution would be the best! Any best practices here?
Do you know how I may solve this in Android?
Things that are on top from a Z-axis standpoint get the input events. Hence, your choices would appear to be:
Create an immediate subclass of
View
where you do everything yourself, dispensing with theImageButton
(or whatever it is you are using now).Attempt to create a composite custom
View
and delegate relevant input events to the underneath widgets, which may or may not be possible.Find some way of achieving an acceptable look that does not imply having something over top of the button.
I am assuming that by "button" you mean an ImageButton
where you have replaced the background to be your own StateListDrawable
-- otherwise, nothing you wrote here makes much sense to me.
If so, you do not need an overlay. You can get by with an...ummmm...underlay. Make the underlay (a separate ImageView
) visible or invisible based upon the button state. Make the ImageView
's face and background look "shining" as part of your StateListDrawables
.
精彩评论