12

I have a view that is round and hovering above (-> in z-axis direction coming out of the screen) the main content. When the someone taps the screen I want either the main content to be selected or the view hovering above, when it covers the main view.

So far that works perfectly. I have a round shaped item on a transparent canvas. Meaning you can see everything of the background that is outside of that circle. However, you cannot select it, because it is still the hovering canvas, just with a transparent paint.

Now I'm wondering, to solve this issue, if it is possible to make the view/canvas itself round shaped?


Update

I added an image for better explanation what I try to achieve. alt text

znq
  • 44,613
  • 41
  • 116
  • 144
  • can you handle the collision detection yourself, get an XY on your touch event and if its outside the radius don't handle the input? – Nathan Schwermann Sep 29 '10 at 16:46
  • Well, I already have that. However, I want the touch event than handled by the main layer in the background, e.g. the text box. – znq Sep 30 '10 at 11:17
  • If you return false on the touch event it should pass the even along to the next thing in line. Sometimes this is very tricky to accomplish correctly depending on the layout hierarchy but you are on the right track. If you post your layout xml files and onTouch listeners we may be able to figure something out. – Nathan Schwermann Sep 30 '10 at 19:11
  • @schwiz: I created a separate question for that: http://stackoverflow.com/questions/3832893/android-delegate-touch-event-to-underlaying-view (The reason I created a separate question for that is, because with this question here I still would like to find out if I can have a canvas that is round) I have the return false and also logging the touch listeners, but it doesn't even go to the next element in the hierarchy (the PopupWindow). – znq Oct 01 '10 at 09:29

3 Answers3

4

As far as I know - it is impossible. I have checked the sources of View.java at git.kernel.org and it is based on Rect class - rects define position, size, regions to invalidate etc. ("The geometry of a view is that of a rectangle." - from the comments in View.java)

As for Canvas class - it is usually constructed over Bitmap or GL. Bitmap is definitely a rectange (a matrix), so canvas seems to represent a rectange too. If using GL a viewport is specified (which is a rectangle, too).

It seems to be the most obvious way to check if the coordinates passed to your onTouch() method fit you region and return false if they don't. Then the event will be passed to the View below and it should process the event.

zserge
  • 2,212
  • 2
  • 31
  • 40
  • 1
    Thanks zserge for the detailed answer. The last point mentioned is exactly what I'm doing now, but I have some other issues with that, which I have described here: http://stackoverflow.com/questions/3832893/android-delegate-touch-event-to-underlaying-view – znq Oct 04 '10 at 09:51
1

Probably not relevant to the original asker anymore, but for anyone who's still looking, it looks like this will be added in L: https://developer.android.com/preview/material/views-shadows.html#clip. The View.setClipToOutline method allows you to clip a view to the shape of a rectanglular, circular, or round rectangular drawable.

Patricia Li
  • 1,346
  • 10
  • 19
-3

You need to specify an Android Selector to avoid the default hovering image.

Macarse
  • 91,829
  • 44
  • 175
  • 230
  • Maybe I didn't explain myself correctly, but I added an image to clarify. I don't think that Selector is the solution to that, but if I'm wrong please let me know. – znq Sep 29 '10 at 16:32
  • Can you explain what is that circle? it's an image it should be shown always? it should have a selector? I can access it using the dpad? – Macarse Sep 29 '10 at 20:26
  • The circle is some kind of a "pop-up" hovering above the main layer. It's on the z-axis going out of the screen above the main content view. You can see it like an AlertDialog, but round instead of rectangular and the possibility to select items from the background. – znq Sep 30 '10 at 11:19
  • @Stefan Klumpp: It should work with a selector, can you paste some code to reproduce the issue? – Macarse Sep 30 '10 at 13:06
  • @Macarse: Maybe you're right. Could it be that the link in your answer is wrong and you tried to point me to that one instead? http://developer.android.com/reference/java/nio/channels/Selector.html That's why I was confused and thought what you meant with Selector is not correct. – znq Sep 30 '10 at 14:59
  • Actually after looking at both links again I still don't get how to use a Selector in there. Will prepare some code and add it to my question shortly. – znq Sep 30 '10 at 15:12